AWK: why does $(cat) work for stdin, but $* doesn't?
echo '((3+(2^3)) * 34^2 / 9)-75.89' | awk "BEGIN{ print $(cat) }" The above syntax works fine with the calculated result '1337'. echo '((3+(2^3)) * 34^2 / 9)-75.89' | awk "BEGIN{ print $* }" But the...
View ArticleHow to replace consecutive characters from directory names, recursively
What is the best way to replace all consecutive characters such as _+-."'? from a directory and all sub directory's names using GNU bash, version 4.3, using tools awk, sed, Perl rename or find? AS...
View ArticleIn some places awk doesn't work in pssh command
I am trying to fetch only column using awk in OS commands like uname -a , uptime, using pssh multiple commands, But it's not giving correct output. Using "uname -a" is just an example i have shown, I...
View ArticleChange numbers to random letter in SED
Considering the following number: 145478 I want to replace these numbers with random letters from a to z. My attempt so far: sed -r 's/[0-9]/[a-z]/g' It does not change the pattern to another pattern...
View ArticleTwo-file processing in awk
I have file : result.txt Apple fruits 10 20 30 Car vehicle 40 50 60 Book study 70 80 90 Assume here 2nd column is a feature, 3rd column is Min, 4th column is Median, 5th column is Max. I have another...
View ArticleCompare two files, remove line
I have one file with URL's. Example urls.txt: https://www.indeed.co.uk/cmp/Endsleigh-Insurance/reviews?fcountry=ALL&fjobtitle=Claims+Assistant<br>...
View ArticleHow can I merge files on a line by line basis?
cat file1 foo ice two cat file2 bar cream hundred Desired output: foobar icecream twohundred file1 and file2 will always have the same amount of lines in my scenario, in case that makes things easier.
View ArticleConvert a string of characters to ascii values
I have been searching through the internet on how to do this but have failed to find a way to actually do it.. Basically, I have a series of large dataframes, and I wish to convert one of the column...
View Articleawk store a pattern result to a shell array variable
I am trying to store the result of a pattern matched by awk to a shell array variable. Here's a simplified example of the same: #!/bin/bash declare -a array1=() declare -a array2=()...
View ArticleHow can I store the output of an awk command as a bash script variable?...
This question already has an answer here: How do I assign the output of a command to a variable? 1 answer When operating in the linux terminal I can enter the following: command ''' awk 'FNR==1...
View Articleextract the oldest values from a master file per each code
I need help writing a script that would extract from a master file the oldest records and save them in a separate file. The file contains hundreds of ISIN codes and additional data. For each, there...
View ArticleNested match rules using awk
I have file content as 0::chkconfig --list autofs:: autofs 0:off 1:off 2:on 3:on 4:on 5:on 6:off 1::grep "^PROMPT=" /etc/sysconfig/init:: PROMPT=yes 2::rpm -q prelink:: prelink-0.4.0-2.el5 3::sysctl...
View ArticleHow to check if a package is installed from Bash?
I need to check if a specific package is installed on a machine from within a Bash script. I found something like that but I don't know how use it correctly. dpkg -l | grep "ansible" | awk '{print...
View ArticleHow cut a data file that have colums separated by spaces
I have a data file with 2 columns 1.0000 9.9398383 1.4399 8.0000000 2.5688 7.9393838 1.0000 4.0000000 1.4399 9.0094949 2.5688 3.9932323 1.0000 8.9393993 1.4399 7.3838473 1.5688 2.8337738 I want to...
View ArticleGet Non matching string from file1 to file2
I have two files - file1 & file2. file1 contains (only words): ABC YUI GHJ I8O file2 contains many paragraphs: dfghjo ABC kll njjgg bla bla GHJ njhjckhv chasjvackvh .. ihbjhi hbhibb jh jbiibi I am...
View ArticleFilter lines between matching strings
Have a contents in file similar to below- There are many lines between START & END and might have errors/warnings too. I want to filter out errors/warning lines between START & END and skip if...
View ArticleAwk-compare 2 files using multiple columns and print lines from both files
So I have a two flat files that is in the format as follows File1.txt Customer1 12345 12346 12347 15646 Customer2 14444 14445 File2.txt 12345 aol.com 12347 gmail.com 12346 google.com 14444 yahoo.com...
View Articlecompare two lines and print unmatched words from two files
I have two files,Lets say file1 and file2 file1 has "eipassoc-03cd9117d7188d2 eipasoc-47367a3f eipasoc-bbbddc3 eipassoc-10bbfb6" each one is space delimited file2 has "eipasoc-47367a3f...
View ArticleAWK: Sum columns, write them into a "final" row
My CSV looks like this A 5 3 B 3 1 ... I need to get the sum of all columns and add those to a new line in the CSV so it becomes A 5 3 B 3 1 SUM 8 4 I was able to print the sum of a particular column...
View ArticleHow to use grep to match a string with spaces in it?
Can anyone help me with this: I am trying to extract a time stamp, by matching a string. For this am using combination of grep/awk commands. As the sting has 4 spces before [1] and one after, am...
View Article