awk

awk – combine 2 steps into one

awk – combine 2 steps into one I need to read the output table of transmission-remote to determine if a download is taking place. This is currently achieved with trans="transmission-remote 0.0.0.0:9092 -n $user:$pass -l" [ "$($trans | awk ‘! /awk/ && /n[/]a/ {print $2}’)" == "n/a" ] || [[ $($trans | awk ‘! /awk/ && …

Total answers: 2

How to remove embedded newlines from CSV fields

How to remove embedded newlines from CSV fields I am struggling with processing a file. Normally I should have a line for each host definition. But sometimes, someone split some fields on different lines. Here is an example: "host1","host1","linux server","" "host2","host2","linux server","" Now I would like to find a way (better in bash) to fix …

Total answers: 7

syntax to delete lines

syntax to delete lines I use this syntax to delete lines from 2.txt to 1.txt: awk ‘NR==FNR{a[$0]=1;next}!a[$0]’ 2.txt 1.txt > lines.txt My lines are in this format: email@email.com:something If this line is identical in the two files, I get lines.txt without this, so it’s good, BUT I want to delete lines if the email@email.com is …

Total answers: 2

manipulate ls text output to add path to filenames

manipulate ls text output to add path to filenames I get sometimes files with following ls output format: /etc/cron.d: -rw-r–r– 1 root root 128 May 15 2020 0hourly -rw——- 1 root root 235 Dec 17 2020 sysstat /etc/cron.daily: -rw——- 1 root root 235 Dec 17 2020 sysstat Is there any chance using normal gnu tools …

Total answers: 6

sed to replace in a file, with both old and new strings in files

sed to replace in a file, with both old and new strings in files I want to automatically comment out a code block in PHP file, as below: The original block: // Enable all errors ini_set(‘display_startup_errors’, 1); ini_set(‘display_errors’, 1); error_reporting(E_ALL); The new block with comments: /* For the production version, the following codelines are commented …

Total answers: 3

How to apply AWK to a directory path?

How to apply AWK to a directory path? I have this command: Folder=./GAS/NNN_/Neutral awk -F / ‘{print $(NF-1)}’ $Folder But I got: awk: read error (Is a directory) I have tried: awk -F / ‘{print $(NF-1)}’ $(Folder) awk -F / ‘{print $(NF-1)}’ $($Folder) awk -F / ‘{print $(NF-1)}’ $(echo $Folder) And I got the same …

Total answers: 1

How to add content to a file before the last } character using Busybox utilities?

How to add content to a file before the last } character using Busybox utilities? There is a file with contents { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { "street_address": "21 2nd Street", "city": "New York", "state": "NY", "postal_code": "10021-3100" }, "phone_numbers": [ { "type": "home", "number": "212 555-1234" }, { "type": …

Total answers: 5

Fetch data from a large file based on time and date recursively

Fetch data from a large file based on time and date recursively Fetch data based on date(column 1) and time (column 2). Each date has time in column 2. Based on each date in column1 two files are to be generated which will have all the fields based on time 6:00 to 21:50:08 (day) and …

Total answers: 3

I need to print value from 3rd column when 4th column condition is matched

I need to print value from 3rd column when 4th column condition is matched cat Data.log REPLICAT RUNNING RPGUJ3 02:00:12 00:00:06 REPLICAT RUNNING RPGUJ4 00:00:10 00:00:06 REPLICAT RUNNING RPGUJ3_3 01:00:11 00:00:00 REPLICAT RUNNING RPGUJ4_3 00:00:12 00:00:06 I want to print those value from column 3rd , which is having time greater than or equal to …

Total answers: 2

How to delete rows that contain 0 in the "last column" in a linux terminal?

How to delete rows that contain 0 in the "last column" in a linux terminal? I’m wondering how can I delete rows when the value in the last column is "0" in multiple .tsv files where the last column number might not be the same for all files. And total number of columns varies hugely …

Total answers: 3

How to split a given column's string values in a text file

How to split a given column's string values in a text file I have a text file on a Linux machine with two columns: Column 1 = id_no (most are 5, with some 6 digits long); Column 2 = genetic_markers (all are 50674 digits long); 12345 0102010205 54322 2221110051 123456 1122011510 I want to change …

Total answers: 5

conditions within brace blocks

conditions within brace blocks To make multiple passes on the same input file, this simple case works fine: $ awk ‘p==1{print $1}; p==2{print $2}; p==3{print $3}’ p=1 infile p=2 infile p=3 infile But fail with this change? $ awk ‘p==1{/Jan/ {print $1}}; p==2{print $2}; p==3{print $3}’ p=1 infile p=2 infile p=3 infile I don’t want …

Total answers: 2

adding first 5 characters of a file name to each line in the file

adding first 5 characters of a file name to each line in the file I have many ".txt" files in a folder. For each .txt file, I need to get the first 5 characters in the name of the file and add them to the beginning of each line in file. I also need to …

Total answers: 4