Questions tagged [awk]

A pattern-directed scanning and processing language.

Filter by
Sorted by
Tagged with
0
votes
0answers
5 views

To get the value of specific attribute value as True or False, having uneven columns

I am having one file with the below two lines in the file. I need to check if the value of xpoweredBy is true or false. Many thanks in advance. <Connector clientAuth="false" sslProtocol="TLS"...
0
votes
4answers
22 views

Convert columns that share a match to row

I have a file with the following structure: Locus7625186 GO0004866 Locus7625186 GO0010951 Locus7625186 GO0005615 Locus7625186 GO0016021 Locus7360093 GO0004712 Locus7360093 GO0007093 Locus1507198 ...
4
votes
5answers
144 views

removing rows containing NA in every column

I have a tab delimited file which looks like this: gene v1 v2 v3 v4 g1 NA NA NA NA g2 NA NA 2 3 g3 NA NA NA NA g4 1 2 3 2 I want to remove those rows from the above file ...
-1
votes
1answer
28 views

Shell script- To fetch the content from the specific tag at all occurrence using shell scripting

I have an XML file on my server. In that file, I have many tags in which there is a tag for example, "container" tag. I need to fetch the content of all the container tags content separately. Many ...
0
votes
1answer
97 views

sed/awk/python replace all spaces between characters after string match

I want to delete all spaces between characters after an initial match. An example is exmpl 0 t h i s a r e t he spaces to d e l e t e exmpl 1 m o r e spaces to d e l exmpl 2 o r s m t h completely d ...
0
votes
2answers
28 views

Multiple Character separator for awk command

I have the data as below: p_id^|^data1^|^data2^|^data3 I need to get the 2nd field only data1 Tried multiple tricks with awk command, but unable to find it out. Can someone please help.
10
votes
4answers
257 views

Modify width of first column in file with a variable number of fields, using awk

I understand how to use awk's printf function, but I don't want to specify every field. For example, assume this is my file: c1|c2|c3|c4|c5 c6|c7|c8|c9|c10 c11|c12|c13|c14|c15 I want to format it ...
0
votes
5answers
54 views

Keeping the characters between two specific characters in fasta headers and removing the rest

I am trying to keep the characters in my fasta headers between the first and the second colon. I've failed trying with sed and awk since my coding skills are very limited. In: >...
1
vote
1answer
17 views

How can i use awk/Grep to search a specified column for a variable [duplicate]

I have data like the following: apple pear sugar pizza pizza chicken pasta turkey I want to grep for "pizza" but only grep the fourth column. I know i can use: awk '$4 == "pizza"' However i have ...
4
votes
1answer
64 views

Assign every word from a line to a variable

I am very new to shell programming. I have a file named quaternary_splitted.csv on macOS. Every line has 4 words. I want to take every word from each line and assign it to a variable. Please suggest ...
0
votes
1answer
36 views

Grep to get output after the first instance of a string

I'm currently using a CentOS image from Docker. What I want to do is get a certain value after grep encounters a certain string. In this case the string is 'inet'. What I have done so far: # ...
7
votes
4answers
15k views

Print a string including single quotes and other special characters

How can I write this with an AIX script correctly? My requirement is to write this command in test.txt: clock=$(prtconf -s | awk '{print $4,$5}') I tried this command: print 'clock=$(prtconf -s | ...
1
vote
3answers
35 views

How to compare column 2 and 3 of File 1 and column 4 and 5 of file 2

I have a tab delimited file 1: NC_025345 4569 4950 KX838946.2 NC_025345 16546 17066 KJ641660.1 NC_025345 11996 12085 KX932454.2 And file 2: NC_025345.1 ...
0
votes
1answer
13 views

How to grep/sed a defind part of string that has spaces

I have a log that contains records like: LineFFF 1234567 0002 @2018-06-12T17:02:50 (len:0) 99 OK : jAFoSSYut2iJLmrk6fdQPL4OMRgd1Ybzb6U9MG1GeWKWqXlYPyfzyMVb9zn3 LineFFF 1234568 0044 @2018-06-12T17:...
1
vote
2answers
45 views

Grouping files with name and move them to respective directories using awk

I am trying to group files on the basis of names (first few letters before _) and moving them to separate directories (create new if doesn't exist) using awk. Test data can be created using commands: ...
1
vote
3answers
35 views

Using regular expression to get latest pip package version

I'm trying to parse the output of this pip install to get the latest package version. pip install package== ERROR: Could not find a version that satisfies the requirement package== (from ...
2
votes
2answers
341 views

Transfrom line into two columns

Input: IN22FDX_S1P_WWWWBBBBMMMCCCC_ffg_pre_0.59_0_.72_-40_nominal Output: IN22FDX_S1P_WWWWBBBBMMMCCCC ffg_pre_0.59_0_.72_-40_nominal # ^ # space instead of ...
1
vote
1answer
56 views

How to out the output of the command 'cal' to csv.?

How can I format the output of the command cal -y 2020 as a csv? I want to prepare the calendar in a table processor. Can this be done? I am using Slackware 14.2.
2
votes
1answer
42 views

awk print condition

When i was debugging a file which was written by others, I found one line psql -U crmlocal -h $2 -p 5432 mydb -c "set search_path=$3;$4" | awk 'NR>3 {print l} {l=$0}' I don't know what awk 'NR&...
2
votes
4answers
5k views

How to extract column name (header) from a CSV file which contains the max value in a row?

I am trying to extract the column name with the maximum value in each row using bash script i.e., the column header value or the value from the same column in the first row. I am using the following ...
1
vote
1answer
34 views

manipulating a shell script

I have a shell script which does couple of things like storing values in a variable. As an example here is my script: for i in ../../*.bam do fn=$(basename $i) fn=${fn%_Aligned....
0
votes
1answer
59 views

Making many symbolic links

I have a file samples_long.20Bids.txt with content like this: P2_305_USD16089489L_HJJNWDSXX_L4 P2_307_USD16089490L_HJNMNDSXX_L3 P2_42_USD16089409L_HJM27DSXX_L1 P2_43_USD16089410L_HJM27DSXX_L1 ...
0
votes
1answer
41 views

I am having difficulties during manipulating log file with awk and shellscript(regex) [on hold]

I am very newbie in this field and very wondering around nowadays. I like to manipulate auth.log file into somehow easy strings to read through awk and bash shell script(regex with for or while loop), ...
4
votes
2answers
50 views

Select columns where a value appears more than x times

I have a file with several rows and columns. I want to select columns where the number 2 appears more than x times. My tab separated file looks like this: Individuals M1 M2 M3 Ind1 0 0 2 ...
4
votes
5answers
327 views

extract lines from bottom until regex match

I have this output. [root@linux ~]# cat /tmp/file.txt virt-top time 11:25:14 Host foo.example.com x86_64 32/32CPU 1200MHz 65501MB ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME 1 R 0 ...
1
vote
3answers
28 views

How to move all lines starting from string to the top of the text file in Bash

I have a text file containing text data. I'd like to move all lines starting from XY: and OTP XY: to the top of the file. How can I do this in Bash using sed, awk, other?
1
vote
1answer
1k views

How to automatically detect and write to usb with variable spaces in its name

I am doing the second BASH exercise from TLDP Bash-Scripting Guide, and I have most of it figured out up until the part when it comes time to copy the compressed files to an inserted USB. Home ...
0
votes
1answer
44 views

Problem in using AWK in TCL expect

i am getting problem in using AWK command in TCK/TK unix command: var=`awk -v var1="^$line" -F "|" '$1~var1{print $1 }' sort-address-name-ip.txt | awk -v var2="$line$" '$0~var2'` and i used as: ...
1
vote
2answers
59 views

How to select specific columns from a file with a string separator

I have a file with columns separated by a string. For example: one<xx>two<xx>three<xx>four<xx>five<xx>six one11<xx>two11<xx>three11<xx>four11<xx>...
0
votes
2answers
53 views

Placing matching occurrence number to the left side of the occurrence itself

I have a file with multiple occurrences of the expression ".mp3". I want the first occurrence to become "1.mp3", the second occurrence to become "2.mp3", and so on. It would be something like awk '/ ...
0
votes
2answers
48 views

Extracting multiple strings, according to a pattern, in a bash script

I'm writing a shell script to generate a directory listing. as an input a receive a long html string : https://www.mycompany.com/posts/aureliaflore_china-seoul-startup-activity-6571925510337728512-...
0
votes
1answer
990 views

how to print only Difference in two files using NR=FNR?

we have to print the old entries only Delta(Difference) in File-1 and File-2. newly added enties in files-1 no need to print. on my unix server everyday new report is extracted from system which is ...
1
vote
1answer
63 views

When using AWK with a variable pattern, can't get IF ELSE statement working

The AWK statement uses the variable $ip to search each line, but I need to print the variable $ip NOT FOUND in the ELSE statement for ips that are not found in the config. Can't get it to work with ...
-2
votes
1answer
43 views

syntax error near unexpected token `}'

i have below sniipet in my shell script it is throwing syntax error any way to solve it iftop -i eth1 -t -s 1 -n -N > ifTop.txt th=`awk '{print $8}' ifTop.txt | cut -c 5-6`
4
votes
1answer
148 views

How to extract a value from each column

I have a file with many rows as below. I just want to extract columns 2,3,5,6; but the third column without the 'chr' prefix: Input: 585 ENST00000417324 chr1 - 34553 36081 36081 ...
0
votes
2answers
27 views

Changing columns to row using awk

I have this list: AA 1 AA 2 AA 3 B 4 B 4 C 5 C 6 C 7 C 8 and I want to change it to below output using awk: AA 1 2 3 B 4 4 C 5 6 7 8 Could you please let me know how can I do this using AWK?
0
votes
2answers
45 views

How can i convert uncertain no of line in single line record

I have same question asked here in latest,but i have something different problem. Ex: Input file ****************** .WER + aaa bbb ccc + ddd eee ****************** .SDF + zzz xxx yyy + iii + kkk ...
5
votes
1answer
52 views

Bash/Awk Sorting of files

I have multiple files in one directory minority with different formatting. I wish to separate those with specified format from those without. There's over 500 files which makes it time-consuming to do ...
3
votes
4answers
144 views

Removing a line containing a string in two columns

I have a tab delimited file: TRINITY_DN42298_c0_g1_i1.p1 NA NA TRINITY_DN12995_c0_g1_i1.p1 PF06799 NA TRINITY_DN2326_c0_g1_i4.p3 NA NA TRINITY_DN6047_c0_g1_i1.p1 PF10585 GO:0008641 ...
3
votes
4answers
302 views

Extract specific characters from each line

I have a text file, and I want extract the string from each line coming after "OS=" input file line A0A0A9PBI3_ARUDO Uncharacterized protein OS=Arundo donax OX=35708 PE=4 SV=1 K3Y356_SETIT ATP-...
0
votes
0answers
22 views

How can I prepend the value of a variable to a column in bash? [duplicate]

I have a script that outputs a column of text. I want to prepend each entry in the column with a string stored as a variable. How can I do this? For example, consider the command $ echo -e "john\...
4
votes
4answers
9k views

Easily get a particular column from output without sed or awk

Is there a quicker way of getting a couple of column of values than futzing with sed and awk? For instance, if I have the output of ls -hal / and I want to just get the file and directory names and ...
0
votes
2answers
45 views

filtering rows using awk

I have a file like this which is tab separated: name v1 v2 v3 v4 g1 4.5 2.3 2.1 0.2 g2 10 3 5 2.3 g3 7 2.5 2.8 3.9 Just showing you above a dummy file where I have 5 columns and 4 ...
1
vote
1answer
53 views

How can I get feh to set wallpaper to each monitor according to its size?

I have a directory filled with png files $ tree ~/wallpaper/ ~/wallpaper/ ├── foo--1366x768.png ├── foo--1920x1080.png ├── foo--2048x1080.png ├── foo--3440x1440.png └── foo--3840x2160.png 0 ...
1
vote
2answers
57 views

Extract specific fields from file

I have file contents like below ALARM: 20190507 1 10:00:09.023000000 10:00:09.023000000 ABB < 50> @160 . "AB12345" 12345 - S . ".." "" "" "POSSIBLE DISK ISSUE (N-to-A) (VAMOS)" "POSSIBLE DISK ...
0
votes
4answers
3k views

How to extract log entries from the last hour?

I am looking for a one-liner command to extract log entries that have occurred within the last hour from a Postfix mail log file. Based on this question, I have attempted to manipulate the suggested ...
4
votes
5answers
853 views

Remove partial duplicates consecutive lines but keep first and last

I have log files with a time stamp and six values in each line i want to reduce the amount of data, by removing consecutive lines with the same values (ignoring time stamps) and keeping the first and ...
0
votes
1answer
52 views

Match and Replace a column with awk

I need to replace the column 13 of file 2, with the column 2 of file 1, when column 1 of file 1 matches with col 2 of file 2. file 1 AAAA00000687697 HPNMS AAAA00000693037 GER112 AAAA00000349750 ...
5
votes
3answers
204 views

pruning subdomains of other domains in a file using script (bash, awk or similar)

I have a huge size file (ten thousand entries) comprising of domains (in random order, but no duplicate domains and with an arbitrary number of subdomains), here is a little example: domain.com ...
1
vote
2answers
55 views

Convert mysql response from VM into specific format

Using a shell job I am getting a response from mysql in below text format, In a text way as requested +-------+ |    A    | +-------+ |   36   | +-------+ +-------+ |    B    | +-------+ |  ...