awk questions
Hi LinuxQuestions gurus,
I am trying to learn the awk command for data table manipulation. It seems like a very useful command and I am starting to understand it, but it is still rather opaque to me... How can one make the field delimiter null so that each space is a field? Perhaps to change: abcd to cbad Also, are there easy ways to change all of the fields at once? An example might be adding commas: blah blah blah blah ... blah blah to blah, blah, blah, blah, ... blah, blah Last question: are there shorthand ways of only taking out one field? This would be easier than specifying each field in the print besides the on I'm taking out. "awk '{print $1 $2 $4 $5 $6....}' example.txt" (only missing $3 in order to remove it...) An example might be: abcde to abde Sorry to bombard the forum with awk questions, but this is very helpful for me... Cheers! Will |
Quote:
FIELDWIDTHS variable .... BEGIN{FIELDWIDTHS="1 1 1 1 1 1 ...." Quote:
and somewhat slower you could work with a loop. Code:
for(i=1;i<=NF;i++){if(i!=3){printf $i};printf"\n"} Quote:
Code:
echo blah blah blah blah|awk 'BEGIN{OFS=", "}{$1=$1;print $0}' Cheers, Tink |
Quote:
Code:
# echo abcd | awk 'BEGIN{FS=""}{print $3$2$1$4}' Quote:
Code:
# echo "blah blah blah blah ... blah blah" | awk '{$1=$1}1' OFS="," Quote:
Code:
# echo "abcde" | awk 'BEGIN{FS=""}{$3=""}1' OFS="" |
Thanks!
Thanks ghostdog74!,
Very helpful. Cheers, Will |
If you're using gawk (to which awk is often symlinked), see if you have the gawk info file installed. It's quite helpful, and includes many worked out examples.
|
All times are GMT -5. The time now is 12:12 PM. |