Words Myte Bite

Funny can be whatever you want it to be. The Words and Musings of Paul O'Malley. Sort of a Blog!

05 April
Comments Off

Fun bits of Bash / Awk Shell Fun

Without going into the why’s I thought I would publish these few lines to amuse some of the people I know get the odd ping from this blog.

There are a long list of numbers in Subt, I want to get a running total (that is the awk bit).

Not only that but then I padded all the lines using printf  so that if they were not nine digits long they were padded in front of them.

cat Subt | awk ‘{s+=$1} {print s}’ | xargs  printf “%09d\n” > RunningT

Had I wanted a total then this would have worked:

cat Subt | awk ‘{s+=$1} END {print s}’ > FileContainingTotal

How to select a variable from a long list using a simple gui command.

(the file RunningT is several hundred lines long)

kdialog –menu “select your amount” $(cat RunningT) –geometry 700×400

(no I don’t know how to do that with zenity, or even if it can be done {yay for kludge})

Now if that is not enough fun, get a giggle at this one:

cat RunningT | awk ‘{ print FNR “\t” $0 }’ > foo

Yes folks we can add an  line number to the file RunningT and create a new file called foo for no good reason.

The ways you can do this are many.

Cut lines off top of file three of them and park them somewhere.
head -n3 SourceForComputation > HeaderPrep

tail does the other end of the file

One of the problems I had with this little adventure was to insure that specific content was always placed in the the file but it could be scattered around the place (I would be splitting the file later)

You can use sort, however that might put your data in a strange place.

So grep for that special_data to extract it  and redirect it to a holding file.

Fine how do you remove specific data from a file so you don’t duplicate your processing of it?

grep -Ev What\ I\ Want\ Removed  File-to-remove-data-from > Result

 

(woops I had first published this as Ve)

and we get a Result

Anyway that was just a few notes on the fun parts of processing data using bash and awk

 
Comments are closed.