Skip to content

Tag: awk

Linux awk command with pipe

Can anyone tell me what the below linux command does: I know tail -5 test.log | grep ‘Start Calculate’ looks for the 5 last lines containing ‘Start Calculate’ in test.log. But then I don’t get what awk does? Answer tail -5 test.log take the 5 last lines of the test.log file then …

Use awk to create file

I have a file that contain : Mr Q 01629699998 Ms Nhung 011287633 … I would like to use this awk ‘{print “BEGIN:VCARD”;print “Name:”$0;print “TELEPHONE:”$0;print “END:VCARD”}’ file to create this result BEGIN:VCARD Name: Mr Q TELEPHONE:016296999…

How to format decimal space using awk in linux

original file : now i need to control third columns with 6 decimal space after i tried awk {‘print $1,$2; printf “%.6ft”,$3’} but the output is not what I want result : that’s weird , how can I do that will just modify third columns Answer Your print() is adding a newline charact…

awk in non-interactive is leaving some data missing

I’m running an awk command in a shell script, and it’s breaking the datafile. All of the data doesn’t load, and there’s a newline character at the end of each line. If I run this as a command, it works perfectly. I’ve just found that i can use fflush() and it seems to have solved…

Get information in the Log file

I have a log file and below is sample log in that file. I changed only here column 3rd and 4th as SourceNo,Destination for reference. my requirement – I need to get separately, Source wise total count that sent to Destination begin with 44 code. i tried with grep and awk but it didn’t work. apprec…

How to group by two fields using bash scripting?

Here is one example of one line of log: I know how to group by one filed, so this is the solution: and this would be results: My question is that how can I group by two fields instead of one, first should be $11 and second is $10? So results should change to: Answer how can I group by

Getting unexpected newline error while doing awk

I am running the following script in linux command line: I am getting the following error: I believe the quotes and spaces are consistent, but why am i still getting this error? Output of ps -ef | grep “java -Droute=full” Answer The actual problem you’re trying to solve is something like &#8…

replace text between two tabs – sed

I have the following input files: and I am trying to find the second string between the two tabs (e.g. text2, abc2) and replace it with another word. I have tried with but it only deletes the tab and does not replace the word. I appreciate any help! Answer I would suggest using awk here: Set the input and out…

Syntax error at or near {

I have an assigment where I have to count the number of words in each .c .cc and .h file.The problem is it keeps showing the syntax error at line 8 and 10 at or near { .This is not a finished script!It may have some other problems but I only needed help with the syntax error! Answer Inside an