Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
sebastiancarlos ( sebastiancarlos@lemmy.sdf.org )  to Linux@lemmy.ml ·
edit-2
3 years ago

cat vs sed vs awk

lemmy.sdf.org

message-square
18
link
fedilink
26

cat vs sed vs awk

lemmy.sdf.org

sebastiancarlos ( sebastiancarlos@lemmy.sdf.org )  to Linux@lemmy.ml ·
edit-2
3 years ago
message-square
18
link
fedilink
alert-triangle
You must log in or register to comment.
  • bionicjoey ( bionicjoey@lemmy.ca ) 
    link
    fedilink
    arrow-up
    4
    ·
    3 years ago

    I feel like you can’t compare these tools without talking about cut. I personally never use awk, but cut and other coreutils can be used together to achieve much of the same

  • narshee ( narshee@iusearchlinux.fyi ) 
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    3 years ago

    cat
    while read -r l; do echo "$l"; done <

    cat -e
    while read -r l; do echo "$l"$; done <

    cat -n
    n=0; while read -r l; do n="$((n+1))"; printf '%5d %s\n' "$n" "$l"; done <

    cat -b
    n=0; while read -r l; do [ -n "$l" ] && n="$((n+1))" && printf '%5d %s' "$n" "$l"; echo; done <

    • gmg ( gmg@beehaw.org ) deleted by creator
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      3 years ago

      deleted by creator

      • narshee ( narshee@iusearchlinux.fyi ) 
        link
        fedilink
        arrow-up
        1
        ·
        3 years ago

        ; was missing

  • fox ( fox@vlemmy.net ) 
    link
    fedilink
    English
    arrow-up
    3
    ·
    3 years ago

    love cat -n, when working with csv files I often use a command like this to figure out which column I need:

    head -n1 file.csv | sed 's/,/\n/g' | cat -n

    • sebastiancarlos ( sebastiancarlos@lemmy.sdf.org ) OP
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 years ago

      Sweet

  • BarrierWithAshes ( BarrierWithAshes@kbin.social ) 
    link
    fedilink
    arrow-up
    2
    ·
    3 years ago

    for me it’s grep but i’m amazed how many searching tools there are on Linux. sed, grep, ripgrep, cat, find, walk, sor, locate, awk, etc.

  • falsem ( falsem@kbin.social ) 
    link
    fedilink
    arrow-up
    1
    ·
    3 years ago

    I pretty much always use these commands unless I need regex or something. I think it’s a lot more maintainable by other people since awk and sed have their own unique syntax.

Linux@lemmy.ml

linux@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !linux@lemmy.ml

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word “Linux” in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

  • Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
  • No misinformation
  • No NSFW content
  • No hate speech, bigotry, etc

Related Communities

  • !opensource@lemmy.ml
  • !libre_culture@lemmy.ml
  • !technology@lemmy.ml
  • !libre_hardware@lemmy.ml

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1 user / day
  • 1 user / week
  • 491 users / month
  • 5.65K users / 6 months
  • 1.31K local subscribers
  • 68.1K subscribers
  • 8.11K Posts
  • 108K Comments
  • Modlog
  • mods:
  • AgreeableLandscape ( AgreeableLandscape@lemmy.ml ) deleted by creator
  • nooter692 ( nooter692@lemmy.ml ) 
  • MarcellusDrum ( MarcellusDrum@lemmy.ml ) 
  • Arthur Besse ( cypherpunks@lemmy.ml ) 
  • Cyclohexane ( cyclohexane@lemmy.ml ) 
  • d3Xt3r ( d3Xt3r@lemmy.nz ) deleted by creator
  • BE: 0.19.21
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code