AWK is a text-processing language. It is mainly used to manipulate and process structured data, and to generate reports.

learn more… | top users | synonyms

1
vote
2answers
26 views

How can I print everything before a match?

After I run hostname I get the FQDN like so: $ hostname foo.mydomain.xyz I'd like to only get the short name foo so I can store it as a variable in a script. I've tried some ways with awk by ...
0
votes
1answer
26 views

Awk script to run a command based on condition using 'if'

I have a piece of code here that basically takes a file called 'srcip' (which is just a list of IP addresses) and compares it to my '~/db' file which is just a tab delimited IP HOSTNAME database of ...
1
vote
2answers
29 views

reverse print without trailing

I have a bash file calling a dns zone and have piped out the fqdn which I need to output in reverse. The snippet below does that fine except I get a trialing . at the end which I don't want creating ...
2
votes
2answers
27 views

Replace Line Breaks on matching lines, using AWK

I have the following data What i'd like to do is for every line, where there is no ,"555" at the end, I want to remove the the line break, \n, and replace it with space. So, the 'matching line' ...
1
vote
1answer
21 views

Get a range of lines from a file and replace a line in that range using awk or sed or both

I would like to replace a line in a section of the smb.conf file using either awk or sed or both if need be. Here's the section in the file... [CMI] oplocks = no wide links = no writeable ...
0
votes
1answer
20 views

Extract text between two slashes and add it at the end of the line after a tab character

I have a text file looking like this: data/CON/001/raw_series_ST_MC_REG_SM.nii data/PAT/001/raw_series_ST_MC_REG_SM.nii I would like to achieve something like this: ...
0
votes
1answer
29 views

word boundary in a awk command not working when printing a range of lines

I am attempting to parse samba .conf file for a specific share section... [CMI] oplocks = no wide links = no writeable = yes delete readonly = yes path = /LOCALSITE/CMI ...
1
vote
1answer
60 views

Script to reference another file first

Hi I have a script and in it I need to get the hostnames from IPs that the script generates. The script will generate those IPs into 1 neat file with only 1 column. It is literally just IP address (1 ...
0
votes
1answer
27 views

How to use the awk to print the output

This command nstats gives me output like below. How can I use awk or grep to give me the uptime with only days on it? I cannot use the "" to get the output. HOSTNAME LOAD MEMORY SWAP PROCS ...
0
votes
1answer
38 views

I'm trying to mirror dns queries generated by TCPDUMP filter and replay them with dig or any other utility

I'm not a very experienced script writer at all. I did find some useful hints in generating an stdout from tcpdump that generates a live feed if you will which is what I want, the problem is handling ...
-1
votes
2answers
29 views

how to split a hex file into two hex files at the first match of certain criteria in perl or just unix scripts

I have a HEX file containing following, I want to split them into two HEX files based on the address: file_in.hex @00000000 00 FC 00 20 89 01 00 00 D9 01 00 00 DB 01 00 00 DD 01 00 00 DF 01 00 00 E1 ...
4
votes
1answer
48 views

writing an AWK command

My input file has three columns like the one below Input file: water 123 wa water 123 at water 123 te water 123 er rater 347 ra rater 347 at rater 347 te rater 347 er ...
1
vote
5answers
58 views

Turn comma-separate rows into 1 column

I have a list of users basically from /etc/group, Id like to basically format that line into one column, I just need the users. So if a field looks like this: bob,john,jane,sam,joyce Then I'd like ...
1
vote
3answers
99 views

Parsing the output of “uptime” with bash

I would like to save the output of the uptime command into a csv file in a Bash script. Since the uptime command has different output formats based on the time since the last reboot I came up with a ...
0
votes
1answer
49 views

output awk print to two separate files

Here is my current code md5sum filename.iso | awk '{print $1} {print $2}' This gives me two separate lines. The first line is the md5 of the file and the second line is the name of the file. I ...
0
votes
1answer
17 views

Sort piped to uniq unexpected output

I have a file that looks like this: "string",192.168.1.0,,TX,192.168.1.2,,,100,0,0,10,10,10,, "string",192.168.1.0,,TX,192.168.1.1,,,100,0,0,10,10,10,, ...
1
vote
1answer
39 views

How to convert a column of hex to dec in gawk, strtonum in gawk gives erroneous results

I am trying to script a database from a network stream. The network stream after being heavily sed'd drops a three column file that looks something like this called file.db ...
0
votes
1answer
40 views

Replace negative values in a file with zeros

I want to replace all negative values in a file with zeros. How can I do this in awk? I tried with gsub but gsub(-*, 0) doesn't work... Any ideas? My "code" is awk '{gsub($(!/-/),"0",$2); print $1 ...
0
votes
1answer
62 views

How to capture diff output from find command exec?

I am using Ubuntu (Precise 12.04) I am trying to write some bash script to see if file is changed via awk replace by using diff command. I did a test with the following: #! /bin/bash diff fileA.htm ...
0
votes
1answer
86 views

How to replace a line in an xml file with a set of lines stored in a variable or file using unix commands?

I have a xml file in which the line that needs to be searched is: SEARCH='<?xml version="1.0" encoding="UTF-8" standalone="no"?><SSC>' This searched value needs to be replaced with ...
-1
votes
1answer
33 views

editing column of a text file

abc.txt consists of two column data as 1 A1021 2 A1021 3 A1022 4 A1022 I want another test file, say pqr.txt (replacing A1021 by 1 and A1022 by 2 and so on). I used the following usual perl ...
0
votes
1answer
44 views

Does an awk script or command execute itself to every line it reads?

I got an awk script named my_awk: #!usr/bin/awk -f { if ($1 == "#START") { FS=":";} else if ($1 == "#STOP") { FS = " ";} else { print $3} } And I invoked it through: cat my_file | awk -f ...
0
votes
1answer
31 views

Using Grep or AWK to find all of the occurences of a specified string

I have a massive single line of data and I am trying to find the occurrences of a specified string. I then want to export the occurrences (-/+) 20 characters to another file. Can anyone offer a ...
0
votes
1answer
86 views

How to add a prefix to every row of a particular column in a csv file via command line on linux

So basically i am trying to achieve the following.    File before editing.  column-1,   column-2,  column-3,  column-4,  column-5 Row-1-c1, ...
2
votes
4answers
76 views

Extract lines based on long list of line numbers

I have a long list of line numbers (35389208) that I do not want in my file. By line number I mean the line in my file (e.g. line 277). My list of line numbers I do not want looks like: 277 278 279 ...
0
votes
1answer
71 views

Perform a GROUP BY-like command in UNIX

I am having a text file like the following: 1 2 3 4 5 6 7 8 9 ... n <-- column numbering 1 0 0 1 0 0 0 1 0 ... 0 0 1 0 0 0 0 0 0 0 ... 1 1 0 0 0 0 0 0 1 1 ... 0 0 1 1 1 0 1 0 0 0 ... 0 0 1 0 0 ...
1
vote
4answers
364 views

Randomly shuffle rows in a large text file

I have a text file of ~1GB with about 6k rows (each row is very long) and I need to randomly shuffle its rows. Is it possible? Possibly with awk?
0
votes
1answer
87 views

How to grep values under columns

How can I grep for a specific column name and display the value underneath that column. Sample data: StandByFile StandByPg StandByLSN StandByRcvBufUsed S0082160.LOG 621668 ...
1
vote
2answers
87 views

Replacing every 10th pipe with new line in unix

Lets say I have fields: name, number, id I have a data file: name1|number1|id1|name2|number2|id2...etc I want to replace every 3rd pipe with a new line or '\n' so I get: name1|number1|id1 ...
-1
votes
1answer
28 views

Which regular expressions (POSIX or extended) are allowed in awk?

I'm wondering which kind of regular expressions (POSIX as in grep, or extended in egrep) am I using when type in regular expressions in awk?
0
votes
1answer
58 views

awk used with grep - no output

I have a bashscript which uses grep with awk as following: #ec2-describe-instances | grep -i instance | awk '{print "Creating -> " $3; system("ec2-create-image " $2 " --name " $3 "-$(date +%F) ...
1
vote
2answers
39 views

How do I print multiple sections in a text file?

I have a text file looking something like this: *FILESTART line_a line_b line_c *INCLUDE file_A.key file_B.key *INCLUDE file_1.key file_2.key file_3.key *SOMETHING_ELSE line_x line_y line_z *END I ...
1
vote
1answer
22 views

Print every line but conditionally only fragments for some lines

I have a text file that looks like this: rno-miR-344-5p miRPlus_11239/mmu-miR-383/rno-miR-383 hsa-miR-301a/mmu-miR-301a/rno-miR-301a ...
0
votes
1answer
96 views

how to extract last number sequence in an IP Address (using Linux)

I want to extract the last digits of an IP Address based on the result of ifconfig command. ifconfig often includes a whole heap of output so I'm not really sure how to get the digits that I want. ...
0
votes
1answer
87 views

Regexp based editing of content in large CSV files [duplicate]

I wanted to remove certain pattern of contents based on a regex from csv file which is very large in size containing 100,000+ records, how is it possible via windows commandline? I also have sed and ...
-2
votes
2answers
69 views

Trying to count and print song file names using awk

RANK NAME BAND YEAR GENERE DOMESTIC/INTERNATIONAL 206:Reach Out, I'll Be There:The Four Tops:1978:Pop:3/2 207:Bye Bye Love:The Everly Brothers:1950:Classic:3/2 ...
0
votes
1answer
39 views

I have file called songs and i'm trying to find the longest and shortest song name using AWK

RANK NAME BAND YEAR GENERE DOMESTIC/INTERNATIONAL 206:Reach Out, I'll Be There:The Four Tops:1978:Pop:3/2 207:Bye Bye Love:The Everly Brothers:1950:Classic:3/2 ...
0
votes
1answer
431 views

Piping tail -f into awk

Greeting, I am trying to pipe tail -f into awk to monitor a logfile in realtime, but according to examples, there should be not problem but I can't get it to work. here is the command I'm running ...
0
votes
0answers
117 views

stdbuf not working while unbuffer does

I am trying to apply timestamps to stdout of a process. For the proper timestamps to be applied, I attempt to unbuffer stdout of the process. This works with unbuffer but not with stdbuf as I would ...
2
votes
1answer
33 views

Weird behavior of awk

Why do I get only "cat" when I run awk 'BEGIN { animal[three] = "hen" animal[two] = "dog" animal[one] = "cat" for (var in animal) { print animal[var] } } ?? Shouldn't it print ...
0
votes
1answer
90 views

Bash Sum Average numbers in files

I have a series of files with 2(two) lines. The first line contains a whole number (1-100) while the second line contains a decimal number(1.0000-99.9999). I need to get the sum of the first line and ...
0
votes
0answers
35 views

awk remove sign “,” in all columns, if it exists between

My data input file: 508,186,,Name,"VIA PAS, 4",vou1@mail.com, 291,345,,Name2,Votros 73,vou2@mail.com, 911,733,,Name3,zap 101,vou4@mail.com, 9000,32,,Michel,hops 12,"x1@mail.com, vou7@mail.com, ...
0
votes
1answer
85 views

How to find the matching records from 2 files in unix

I have two files which contains email_ids. 1. Test1.txt 2. Test2.txt Test1.txt contents are: abc@gmail.com xyz@gmail.com mns@gmail.com Test2.txt Contents are: jpg@gmail.com joy@yahoo.com ...
0
votes
0answers
6 views

Grep values from nethog and netperf [duplicate]

I need to monitor the network activities of a process and the bandwidth of the connection. So I decided to use nethog and netperf combine with grep and awk to write the values to a file. nethog ...
0
votes
2answers
146 views

Grep values from nethog and netperf

I need to monitor the network activities of a process and the bandwidth of the connection. So I decided to use nethog and netperf combine with grep and awk to write the values to a file. nethog ...
1
vote
2answers
82 views

moving directories after grep

I have isseued the next command in order to move some directories to the "build_tools" folder however the result was not the one I expected. ls -l | grep 2014-03 | awk '{if ($8!=build_tools) print ...
-2
votes
1answer
70 views

awk to print the line number of a closing bracket

I have a file 1.txt ejryheiur rewurie ( ejwhrejkrh rewrhwe rewkhrwe rewhkr ) dfhgsdfh rqwergjweg jhwgrh ( rehgwrwhe rhwejkr ) With this nawk script nawk ' BEGIN { ...
0
votes
2answers
110 views

Replace string in string but not when its somewhere between double square bracket

I have a long string from mysql field containing the data of a mediawiki page. I have to replace a string in that mediawiki page but not when the string is in mediawiki link. The mediawiki link is ...
0
votes
2answers
64 views

Replace words on given line numbers

I have a file 1.txt INTEGER-d_int () INTEGER-d_int () INTEGER-d_int ( ) INTEGER-d_intClass() INTEGER-d_intClass new() and I want to replace the occurrence of d_int with d_INT on the ...
0
votes
1answer
62 views

How to encrypt the mail in unix?

I want to encrypt the mail as that will be containing the confidential information. There are no attachments. Please help in providing the steps to encrypt the mail. I have got the reference of How ...