Tag Info

New answers tagged

1

You are missing a space in your cut command. cut -d\ -f1 should be cut -d\ -f1 since you are using \ to escape the following space (using space as the delimiter), and arguments are separated by a space, there is a missing space between the -d and -f (for cut it looks like you are trying to use " -f1" as a delimiter, which is more than one character). ...


1

You can use: awk '/%idle/ {for (i=1;i<=NF;i++) {if ($i=="%idle") col=i-1}} /^Average:/ {print $col}' This stores the column where %idle is and substracts one because Average: does not have the PM/AM column. Then, it prints that column when the line starts with Average:. Test With sample1: $ awk '/%idle/ {for (i=1;i<=NF;i++) {if ($i=="%idle") ...


0

cat takes a filename as its argument. You definitely need echo. What you may have wrong is that the line read will be space-separated, so cut needs a -d " ". However, why not use the -r option of read ? $ read -r NAME FNAME AGE FILE < file $ echo $NAME Doe $ echo $FNAME John $ echo $AGE 36 $ echo $FILE johns_letter.pdf $ echo $FILE | sed -e ...



Top 50 recent answers are included