awk - pattern-directed scanning and processing language

learn more… | top users | synonyms

1
vote
2answers
80 views

How can I format a flat file using awk?

Below is the format of some table data contained within a single file: ;NULL;ABCD;ABHJARS;;ABCD;ABCD;Y;;;;;;;;;A; ;NULL;XEU-ANKD;XEU-AJKD;;ABCD;ABCD;Y;;;;;;;;;A; . . ;11744;AMKDIONSKH;AMKDJ AN DJ ...
4
votes
4answers
287 views

remove blank lines in awk display

I was trying to figure out a solution for this question. I wanted to use awk for the solution. My input file is something like below. -bash-3.2$ cat file ramesh ramesh_venkat ramesh3_venkat3 ...
0
votes
1answer
65 views

Please explain the Awk script provided below

Can anyone please expain me step by step below AWK script written. I have the below code written in my script to format the flat file data. Just wanted to understand so that i can reuse -- I am not a ...
0
votes
2answers
47 views

Method to paste specific column when in terminal

I'd like to paste only the third column of data from within the terminal. I originally have something like: 4 SF0086 SF0086 12 SF0087 SF0087 17 TSF141 TSF141 29 TSF070 TSF070 30 TSF028 TSF028 31 ...
6
votes
3answers
500 views

Is there a perl or awk solution for this problem?

I have an input file (input.txt) like below. id1 id2 name weight 53723848 12651711 timburnes 1.36667 53530214 12651711 timburnes 1.51191 53723848 53530214 timburnes 1.94 764157 ...
-1
votes
1answer
52 views

Unix Awk group by

Can anyone shed me light how to group by based on the username and sum the values divide it by number of rows of that specific username. for example below. root 25 oracle 25 batch 30 griduser 20 ...
0
votes
2answers
105 views

what does getline do inside awk?

I have this following awk script that takes the following input file, input.txt and produces the output below. Can someone please take the time to break down how this awk script works? I've spent a ...
4
votes
7answers
318 views

How can I groups numbers in a file

I have a file with numbers in float format. I can review them via sort -rn numbers.txt | less I would like though to be able to "group" them. I.e. easily see how many are in the same range. To give an ...
1
vote
1answer
79 views

Using awk for data manipulation

I have an input file in the following format. #track chr11 61731756 61735132 FTH1 - chr12 6643584 6647537 GAPDH + chr11 18415935 18429765 LDHA + chr12 21788274 21810728 ...
2
votes
1answer
71 views

Pipe hex characters to awk

This command works as expected $ awk 'BEGIN {print "\x41"}' A As does this $ printf '\x41' | awk '{print}' A However when you rely on awk to recognize the hex characters, it fails $ echo '\x41' ...
1
vote
1answer
114 views

Parse/Manipulate in awk

I am new to awk programming. I have a question on manipulating text file, which is required to draw certain network based images in a visualization software (Circos http://circos.ca) I have input ...
10
votes
9answers
1k views

How can I print the longest number in a string?

I am looking for a method to print the longest number in a string. E.g.: If I have the string 212334123434test233 how can I print 212334123434 ? Note: I am looking for the longest continuous ...
1
vote
2answers
70 views

Parse,Manipulate Data In linux/Unix

I want to have exactly the same output in this post(http://unix.stackexchange.com/questions/126139/extract-data-in-linux-unix)as above,but I have a new input file,which is below: ABCB11 4 ACE 11 ...
1
vote
2answers
161 views

Extract data in linux/unix

I have input data which I want to parse and extract values using awk/grep/sed: group-2 9 10 text color=black,from=ABCB11,fromid=4,order=2,thickness=3,to=ACE,toid=11,use=1,z=1 group-3 0 1 text ...
-4
votes
1answer
115 views

Write a script file 'account.awk' that from a file 'orders' creates the formated printout of account

Write a script file account.awk that from a file orders creates the formatted printout of account. The file orders is as follows: http://pastebin.com/kPF5B0c0 Beside the column Cost the account ...
2
votes
1answer
209 views

Regex doesn't work with grep

I have a string like this TEST="/dev/sda1 on /media/sda1 type vfat (rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,quiet)" (Result from mount | grep sda1) ...
1
vote
2answers
85 views

How to multiply two columns in awk?

I want to multiply column 1 with column 2 (till end of file) in input file and should output 1 column and multiplied 3 column in separate file. input.txt 1 677679866 2 121867616 3 49413198 4 ...
0
votes
2answers
108 views

Compare first column in different files

I want to compare one file with other files in the same directory. file1.txt contains: move 34#123# get 11#278 put 33#29#567#23 file1.txt should compare with files 1.txt and 2.txt. 1.txt ...
0
votes
1answer
44 views

How can I print a specific occurence of a range pattern?

I am trying to extract several data fields out of somewhat peculiarly formatted strings. Each string has a format similar to the following (spaces added for emphasis): 1 abcd 2 1 efg 2 hij 3 ...
7
votes
5answers
332 views

SED : Case Match Pattern Replacement

I have a source code spread across several files. It has a pattern abcdef which I need to replace with pqrstuvxyz. The pattern could be Abcdef (Sentence Case) then it needs to be replaced with ...
3
votes
2answers
297 views

How can I print out all but the last n characters in bash?

I'm working with standard input (cating two files together) and want all but the last 10 characters of the result to be passed through the next command. All I can find through searching is using sed, ...
3
votes
2answers
79 views

Printing in awk up to specific line and 5 more results

I'm trying to print out all the lines up to the appearance of a particular song and 5 more songs with that. The problem i'm new to the shell what I have to fix in the bellow commands? RANK NAME ...
2
votes
1answer
43 views

I'm trying to count and print song file names using awk as following

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 ...
3
votes
3answers
174 views

Rearrange text file by prepending data rows with header row

I have a file whose content looks like this: 2009 150 0 0 0 0000 75.316 0.0400390625 0.00007 0.00000 0.8980 76.216 0.0400390625 0.00007 1.00000 0.9046 77.217 0.0400390625 ...
3
votes
3answers
88 views

Append columns in a text file to after the final row

A smaller version of many data files I have looks like this: 0 0 0 0.05 9.6877884e-06 0.0024898597 0.1 4.2838688e-05 0.0049595502 0.15 0.00016929444 0.0074092494 0.2 0.00036426881 0.009839138 0.25 ...
-1
votes
1answer
56 views

How to assign variable in awk

I have a code like below: $ awk -F'[]]|[[]' \ '$0 ~ /^\[/ && $2 >= "2014-04-07 23:00" { p=1 } $0 ~ /^\[/ && $2 >= "2014-04-08 02:00:01" { p=0 } ...
1
vote
3answers
62 views

Print the number of values which have the special characters in them

I have a text file like the one below. I want to check the second column and print the count of values which have some special characters in them. 101,aaa,d01 102,*&%,d02 103,$%&,d03 ...
2
votes
2answers
92 views

Merging multiple lines based on column 1

I have a file like below.. abc, 12345 def, text and nos ghi, something else jkl, words and numbers abc, 56345 def, text and nos ghi, something else jkl, words and numbers abc, 15475 def, ...
3
votes
4answers
196 views

merge 2 rows based on the same column values

I have a file like below. 47196436 47723284 name1 1.77273 42672249 52856963 name2 1.06061 52856963 430695 name2 1.16667 55094959 380983 name3 1.55613 17926380 55584836 name4 1.02461 3213456 34211 ...
2
votes
3answers
94 views

awk - to add a column after matching the remaining columns

I have a file (file1.txt) with the contents as below. 8145216 3377090 1.5 1405541 53595498 1.53637 I need to generate all the possible combinations for the first 2 columns in the above file. I use ...
1
vote
1answer
38 views

linux if else fails for some IP's

i am using the following code with if then to mount. It works for some IP's, it does not work for some IP's especially for FAILURE statement. Here is the code is_mounted() { mount | grep -qohw ...
6
votes
4answers
810 views

How to extract logs between two time stamps

I want to extract all logs between two timestamps. Some lines may not have the timestamp, but I want those lines also. In short, I want every line that falls under two time stamps. My log structure ...
2
votes
2answers
158 views

How to do alphanumeric validation for a particular column (say $2) of a file using awk?

How do I perform alphanumeric validation for a particular column (say $2) of a file using awk? For example I've tried: awk -F, '{if ($10==(/[0-9a-zA-Z]/)) count+=1;} END {print count}' final.csv I ...
0
votes
2answers
77 views

Extracting with grep/sed a first pattern and then a second pattern that occured some lines before and related to the first

I'm trying to extract a specific line from a .htm file when a pattern occur ("Event 100" in my example below) but at the same time I need to retrieve also another pattern which is related to the first ...
1
vote
1answer
66 views

AWK - every thing in one line? [closed]

Hello can I make several changes in a file using just on line with awk? For example, transform this: awk < towhee_input5 -v k="$nstep" 'NR==18 {$0=k}{print}'> towhee_input6 awk < ...
2
votes
3answers
234 views

Merge 2 files based on all values of the first column of the first file

I need to merge below 2 files: file1: TABLES REF-IO HEAD-IO DIFF-IO test 200 500 -300 exam 2 3 -1 final 2 1 1 mail 4 2 2 TOTAL 208 506 -298 ...
1
vote
2answers
204 views

How to replace a custom date string in a text file

I've looked through several tutorials and a couple of StackOverflow posts, but I've not seen any examples using sed or awk which use dates. I have a text file that contains this as the first line, I ...
4
votes
7answers
515 views

How to split a filename list in 5GB sets?

I have a pretty big list of files which I like to group in smaller list of 5GB each for further processing. The file list is in the following form: "size" (from du) "tab" "absolute path", like this ...
3
votes
4answers
246 views

extract the characters before () using grep

I need to extract the characters before the character '('. My file structure is: rose(good)ook daisy()no lilly(bad)fine sunflower()nice I need output file as in the form of: rose ...
1
vote
3answers
60 views

awk want to total by hour and variable

I am able to run this and it works fine - note: field $1 is a time/date stamped field.. gawk -F ":" "{ print $1 }" /cygdrive/c/counting/ourlog | sort | uniq -c | sort -r 57339 2014-03-21 09 54290 ...
1
vote
1answer
63 views

Remove the string before the whitespace

I want to remove a word before the whitespace. My file structure is: ant tiger static rabbit lion dynamic monkey donkey I need the output as: ant tiger rabbit lion monkey donkey ...
3
votes
2answers
71 views

introduce line break at the same position based on another file

I have 3 input files all having the same number of lines. I have come up with a movie example to make the question look interesting. file1.txt -- Essentially contains the actor names. ...
1
vote
2answers
105 views

Union of two files and unique in new file

I have two files with few similar column one, two and third column with small variation and few other columns as follows. file 1: AT1 AT22 24 1 ATAGATA ATTATAT AT2 AT24 22 0 ATAGATA ATTATAT ...
5
votes
4answers
474 views

Reduce the over use of files in text processing

Currently, I have a file (Results.txt) which has 27k rows. The file content is as below. 45008657 | A. | | Long | 0 49210987 | A. | ...
3
votes
1answer
34 views

update line based on previous line

I have a issue since I'm not familiar with awk. I have csv file generated from sar -d output converted to csv style: 12:33:41 unix,restarts 12:35:00,lofi4096,0,0.0,0,0,0.0,0.0 ...
1
vote
3answers
237 views

Extract part of string using grep

I have 3 files in a directory MYO144064T MYO144064TA MYO144064TX Where the digits and 11th character will change. In my csh script, I want to extract the letters 'A' and 'X' probably using grep ...
3
votes
3answers
3k views

How to parse JSON with shell scripting in Linux?

I have a JSON output from which I need to extract a few parameters in Linux. This is the JSON output: { "OwnerId": "121456789127", "ReservationId": "r-48465168", "Groups": ...
3
votes
4answers
190 views

Split the input file with line breaks

I am trying to insert line breaks on a file based on the same names which happens to be the second field in my file. So, my input file is like below. 17412193|name1|organization ...
2
votes
2answers
349 views

How to find and replace a field column value in UNIX

I have file with the value say which is delimited with | 123-|aaa|bbb|123|123.0|123-|123.01-|-123.02|123.03-|aaa|bbb|123-|aaa-|-bbb|cc-cc|123.04-|aa123-|123.05- I need to pick the column values ...
3
votes
4answers
144 views

Identifying genes from a list of genes

I have a gene list file. Some thing like this SWT21 SSA1 NRP1 EFB1 TFC3 MDM10 I have another file which also contains the names of these genes in my list along with other ...