Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [awk]

A pattern-directed scanning and processing language.

0
votes
1answer
20 views

compare column of two files and print data accordingly

I would like to compare the 2nd column of file1- freememory with the 2nd column-usedmemory of file2. If file1(2nd column) that is "freememory" > file2 (2nd column) that is "usedmemory" then print ...
-1
votes
0answers
24 views

awk compare columns in two files . Print data if values from one column is greater than the other

awk - compare two columns of two files such that,Condition if column 4 in file1 is greater than column 5 in file2 -print column 1, 2 from file 2 and column 1 from file 1.The file1 is sorted in ...
0
votes
1answer
21 views

create symlinks by dropping version number

I have large number of shared libraries like this: libexpat.so.1.6.7 libqquicklayoutsplugin.so libstdc++.so.6.0.24 libexportlib.so.1.0.0 libqsvg.so ...
0
votes
0answers
22 views

sed multiply a number in an xml-attribute by factor of ten

I would like to multiply the attribute in viewBox of svg-files by a factor of ten. I want to change <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" version="1.1"> to <svg xmlns=...
4
votes
2answers
142 views

sed or awk: remove numbers after a symbol

I would like to remove just the numbers and "_" after ">" symbol, for example: >1_CR-B_CR56_t MTKIIKFVYFMTIFISPNHHCPVYNCTHPKQPWCKLVRLQLLFHGSLIGLCDCI >2_R-B_R46_t ...
2
votes
2answers
65 views

Sort lines according to date and time

I have this file which represents a calender. Each file has the exact date and time, then the name event and a note. 06-12-2016,12:00,gym,leg day 05-04-2018,12:09,gym,hands 09-08-2019,13:08,movies,...
7
votes
1answer
266 views

awk referring to an array element

#!/usr/bin/env bash awk ' BEGIN { arr[A]=1; arr[B]=1; arr[C]=1; arr[E]=1; arr[J]=8; arr[Q]=10; print arr[J] }' the above command outputs the latest set value for arr['...
0
votes
2answers
41 views

Add new lines above each existing line in a file

I have a file with below lines This is an PLUTO This is PINEAPPLE This is ORANGE This is RICE How do I make a new line above each lines and insert the last string to the new line output as below: ...
1
vote
0answers
35 views

awk delete duplicate [duplicate]

I want to determine if a record contains a duplicate value for a specific field and then delete the duplicate record and save the new file. abc|123|def|456 abc|456|ghi|789 def|123|def|456 I want to ...
1
vote
2answers
91 views

Shell-Script Bash

I have this loop in the shell script, but it seems I don't fully understand what it does: especially gawk -v for ((k=$1; $k<3 + 3 ; k=$k + $3)) do echo $k | gawk -v s=4 '{print $1*s}' done ...
0
votes
0answers
28 views

Comparing record count within a same file [on hold]

I am new to shell scripting . I want count the number of linea in my file and compare it with the record count available in the trailer record.. How to do that? I tried this (wc - l filename ) to ...
0
votes
1answer
38 views

Unix - replace filenames with unique prefixes in a directory with specific unique prefixes from a file in the same directory

I have hundreds of files in a directory with the same suffix and unique alphanumeric prefixes like this: ABC01234.sorted_dup.bam ABC04271.sorted_dup.bam ABC09287.sorted_dup.bam I have a file with ...
-3
votes
1answer
19 views

Comparing two fields from two files and printing the common items from the files with the count from each file

I have two files in a below-mentioned way File1 Emp1 Dec10 12Am Emp2 Dec10 2Am Emp3 Dec10 4Am Emp2 Dec10 6Am Emp1 Dec10 8Am File2 Emp1 Dec11 12Pm Emp2 Dec11 2Am Emp1 Dec11 3Am Emp3 Dec11 ...
4
votes
3answers
332 views

Manipulating text in first column only? [duplicate]

Example Input: foobar@example.com foo@example.com,bar@example.com Example Output: foobar@example.org foo@example.com,bar@example.com So, in "normal" circumstances, it would obviously be easy to do ...
1
vote
1answer
18 views

Awk csv treatment output malformed line to stderr

I have a script that takes several CSV files from a folder and puts them together in a gzip file with one field extracted from the file name : awk -F";" 'BEGIN { OFS = FS } FNR == 1 { match(FILENAME,...
0
votes
2answers
38 views

Calculating Average of a Column only if two Conditions from Separate Columns are Met using Awk [on hold]

I am analyzing my experimental data where I have column 2 = parent colony (there are 3 total colonies: A, C, and E) and column 4 = pH treatment. I am trying to calculate the average carbonate ...
0
votes
2answers
37 views

replace a string from a specified line number and column

I would like to replace from line number 4, the character "K" which is right after 19823 but not the "K" character which follows 19822SOL OW60021 7.173 19822SOL HW160022 7.230 ...
3
votes
4answers
110 views

Search recursive for files that contains a specific combination of strings on the first line

I need to find all files that cointains in the first line the strings: "StockID" and "SellPrice". Here is are some exemples of files : 1.csv : StockID Dept Cat2 Cat4 Cat5 Cat6 Cat1 ...
-2
votes
0answers
18 views

Taking a number from multiple files and put all these numbers in a column form in a single file awk/bash [closed]

I have multiple files with a number in each file. I need to extract this number from every one of these files and make a column of these numbers in a single file. How can I achieve this in awk/bash?
2
votes
2answers
113 views

How to break line after matching case but needs to go back a couple of characters

I have the following sample: 1. TNT 00:00 2. Swing From The Gutters 7:34 3. Ten-Day Interval 13:29 4. I Set My Face To The Hillside 18:16 5. The Equator 24:26 6. A Simple Way To Go Faster Than Light ...
4
votes
1answer
58 views

awk to search the string and count for total in a one liner [duplicate]

I have logs like as given sample below, where I'm simply looking for a SUCCESS string in the log file and counting the total. $ cat ansible.log lnx-host01.tin.com | SUCCESS => {"changed": false, "...
1
vote
2answers
28 views

Filter unique data from text file based on specific columns without sorting

I have various text files with between 10-100k lines following the format below. "2018-12-07 23:21:32",XX,99,ZZZ,250,REMOVED "2018-12-07 23:25:17",XX,99,ZZZ,250,AVAILBLE "2018-12-07 23:29:05",DD,11,...
0
votes
2answers
42 views

Pick off 'first' dates using cal function in bash

I'm trying to pick off the first Monday, second Tuesday, second Saturday, etc. out of the cal function and piping awk commands. For this month, I can get the first Tuesday correctly with the command ...
2
votes
2answers
46 views

Extract all line from a file that contains two strings in any position [duplicate]

I have a .txt file with contents similar to this: 100 150 180 200 300 400 100 200 250 350 380 400 100 160 170 400 450 500 100 120 140 160 180 200 100 120 140 160 180 300 I want to grab all the lines,...
-1
votes
2answers
50 views

How to print the first line which include special word [closed]

Print the first 123 below XXX AAA BCB DDD 123 123 XXX CCC 123 123 MSM 123
1
vote
1answer
28 views

Use awk for values stored in a variable?

I want to do an if statement that compares the values of a command that reads header information of two image files. First I pass output of the command to the variables ~$ hd1=$(<command> <...
0
votes
1answer
23 views

shell script /unix commands for text file content editing [duplicate]

I want to edit the file contents in the 2nd line and 2nd column ,which is a file name from that I want to remove the part after the last underscore and before the file extension . The contents of the ...
1
vote
5answers
73 views

Remove text between consecutive occurences of strings

I need to remove all text between two given strings in a text file. The strings may be located on different lines. For instance, in the following text file @article{ginsberg_lifespan_2018, title =...
-1
votes
3answers
28 views

replace multiple strings in a file in python3 [closed]

I have test file where i have some entries like below and i need to change memberUid to nisNetgroupTriple along with the names $ cat testfile2 memberUid: tony memberUid: jacob memberUid: zenny ...
0
votes
2answers
49 views

Want to edit a file content for Removing the string after the last underscore and before the file extension using Unix commands

I want to edit the file contents in the 2nd row and 2nd column ,which is a file name from that I want to remove the part after the last underscore and before the file extension . The contents of the ...
0
votes
1answer
23 views

awk or bash to read IDs from CSV, match rows in second CSV, change value in 2nd column

I have two .csv items-to-change.txt is a single column list of unique ids: 218294 222084 197931 198161 197432 201021 214009 items-by-location.txt has unique ids and location number (tab delimited) ...
1
vote
3answers
44 views

Awk - print last column or one before last if last is emty

I want to use AWK to get the filename or the last folders name if the string is only a directory. I have: awk -F '/' '{print $NF}' to print the last column and: awk -F '/' '{print $(NF - 1)} ...
0
votes
1answer
28 views

awk: split input string of numbers and do maths on individual character

I have to take a number as the first argument and do maths on individual digits. The program below is supposed to output all the individual digits. INPUT=$1 doMath() { awk '{split('$INPUT',a,"");...
0
votes
0answers
25 views

How to remove all comments from a javascript file using common Linux command line tools?

I have a javascript file with deeply needed comments. Javascript uses C style comments: //this is a single line comment And /* this is a multi-line comment */ However, the actual code looks ...
-2
votes
3answers
41 views

sed/awk string replacement with newline and tabs

I have an XML file that contains the following: <ipaddr>192.168.1.1</ipaddr> <subnet>24</subnet> The goal is to modify <ipaddr>192.168.1.1</ipaddr> to <...
1
vote
3answers
56 views

Sorting filenames uniquely

I have searched for the solution but couldn't find answer to my problem. I have thousands of file in a directory. Filenames are in the below format 74687_1543944930857.txt 74687_1543945090451.txt ...
0
votes
3answers
35 views

remove last number from string

I have a file test.txt, below the content: SCDE1 SF9 STR1D2 SREDF21 FRED STER2R4 I want to remove only the last character if it is the number, so the output should as below: SCDE SF STR1D SREDF2 ...
0
votes
3answers
32 views

Linux Bash and Scripting - Count rows from text file

I'm having issues with displaying the row count displayed from a script I am currently working on and I am using Putty. This script reads a text file that looks similar to user1|login|1 user2|login|...
0
votes
3answers
33 views

How can I parse the output of `ps` to different fields?

I would like to parse the output of ps, to get any field using awk. It seems that ps separate the fields by whitespaces, but the values in COMMAND field usually have whitespaces. Is there a way to ...
4
votes
3answers
156 views

Add lines to files to make them equal length

I have a bunch of .csv files with N columns and different number of rows (lines). I would like to add as many empty lines ;...; (N semicolons) to make them the same length. I can get the length of the ...
0
votes
0answers
46 views

How to extract html between tags?

I need to extract HTML between two tags in shell script. For example: A html document can have multiple <h2> tags like below <h2> <a id="id1" name="name1"></a> test1 &...
-1
votes
1answer
27 views

Linux Compare two files on different field and print field 1 of first file

I have two files like this. file 1 1:apple 2:banana 3:pineapple 4:guava 5:orange and file 2 like this apple guava orange i just want to compare file 2 with file 1 and print the 1st field for the ...
1
vote
0answers
27 views

Cutting output from sudo in a bash script

I am writing a script that is supposed to ask for user's password, do some stuff with it and eventually pass it to sudo. This is roughly how it looks: echo "input password: " read -s password printf "...
1
vote
2answers
46 views

Awk or Sed: If pattern is found: delete line && export variable

In my bashscript I want Sed to find debug: Debug in a file ${SourceP} and if found delete that line and export to the environment Debug=Debug sed -i '/debug: Debug/,+0 d' ${SourceP} && export ...
-1
votes
1answer
39 views

how to add words before line on all the scripts in current folder

under /home/scrript , we have 187 bash scripts all the scripts have the following line: kill -PIPE $PID we want to add the following words before this line on all the scripts as the following [[ $...
0
votes
1answer
21 views

Text filtering from configuration file [duplicate]

We have a config file which consists of more than 24000 lines. I am stuck in one task. I need to segregate the lines starting as below (service definition of specific host in icinga2) Object ...
0
votes
3answers
42 views

remove dots from value

I am trying to write a script that shows me if a service is running or not. command: service ntpd status | awk '{print $5}' output: running... how can i remove those dots? or is there a better way to ...
0
votes
3answers
41 views

How to replace a number by its corresponding string (low/high) in bash?

I have a file: property(Address1, 4.5) property(Address2, 2.2) property(Address3, 9.0) property(Address4, 3.4) --- I want to replace the floating points based on some conditions (For example: if the ...
0
votes
1answer
40 views

Filtering with awk between a range

I have this code that compares genes to a large list of snps on the same chromosome. For this I only want to compare genes and snps that are within +/- 1000000 bases of each other, but when I try to ...
0
votes
1answer
44 views

Compare 2 files and print matching values to a new file

I have a file which contains 12 Million lines each line is broken into 8 parts all of which are separated by ";". File1 Example: AAA;BBB;CCC;DDD;EEE;FFF;GGGXX;HHH Each line has a unique ID in $7. I ...