text-processing

How to use sed to remove newlines above and below a string?

How to use sed to remove newlines above and below a string? I’d like to change all occurrences of ntoken1n and ntoken2n to token1 and token2 in a file). I thought this would do it: ${ N N s/ntoken1n/token1/ s/ntoken2n/token2/ } but it does not. Thanks in advance for any clarification. Asked By: John-L_. || …

Total answers: 4

Need help with Sed command with multiple replacements

Need help with Sed command with multiple replacements I need a file with sed command I have a file like this amb/eng/hello.amb and I need the output to be like below amx/eng/hello.amx amx-grk/eng/hello.amx Could anyone please kindly help me? Asked By: afrin || Source You may try following: sed ‘s/amb/amx/g’ | awk -F’/’ ‘{print $1"/"$2"/"$3 …

Total answers: 3

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

sort in shell using multiple -t

sort in shell using multiple -t I have a file that contains: 192.168.130.175 2014-09-04 10:25:01 /index.html 192.168.138.244 2014-09-04 11:23:00 /index.html 192.168.138.244 2014-09-04 10:29:37 /products.html 192.168.138.244 2014-09-04 11:22:49 /products.html 192.168.83.173 2014-09-04 10:05:17 /products.html 192.168.130.175 2014-09-04 12:24:24 /products/004.html 192.168.130.175 2014-09-04 10:09:13 /products/296.html 192.168.130.175 2014-09-04 11:01:20 /products/296.html 192.168.83.173 2014-09-04 12:19:55 /products/560.html I want to, first, sort by IP …

Total answers: 3

Pull mac address via bash script

Pull mac address via bash script A bit background. Im creating a script that will run on USB stick with Ubuntu. It needs to pull various info from the current laptop its connected to and save it to a file. Right now Im using "lshw -c network >> textfile.txt to pull network information. But it …

Total answers: 3

How to create a new column and add a random identifier to it with miller

How to create a new column and add a random identifier to it with miller I want to add a column with a randomly created "case number" to my csv file. The first 2 letters of the casenumber must be any letter from A-Z in capitals. followed by 5 random numbers. input: COMPANY,NAME,STREET,ZIP,CITY,IBAN Test Ltd,John,Big …

Total answers: 5

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

using bash, create files based on pattern match

using bash, create files based on pattern match we have a file with content as below. /* —————– pattern_1 —————– */ jb: pattern_1 Data: asdflj adfas Log: dir/log1 /* —————– pattern_2 —————– */ jb: pattern_2 typ: CM comm: ${dir}/DISPV mach: au_buh description: "run flag" /* —————– pattern_3 —————– */ jb: pattern_3 typ: fw own: buh …

Total answers: 4

How to convert CR to CRLF line endings on a file?

How to convert CR to CRLF line endings on a file? An ASCII text file, with CR line terminators, (Mac style) needs to be converted to have CRLF line terminators (DOS/Windows style). Search for CR not followed by LF, and replace that CR with a CRLF. So a duplicate command won’t ruin the file (with …

Total answers: 3

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

Reverse sorting of 2 textblocks in larger set of textblocks

Reverse sorting of 2 textblocks in larger set of textblocks I have a list of data, separated into blocks by headlines. The headlines are marked by 6 ‘=’ signs at beginning and end. There is a limited set of headlines that may appear, but not all of them appear every time. They will however appear …

Total answers: 4

I need help making this bash script run faster

I need help making this bash script run faster I have a script that takes a local log file, reads each line, ID’s the card and the IO type, extracts the relevant data string, compares that string to definition files and assigns a T or F value to each bit. It then creates a new …

Total answers: 1

Convert table to json

Convert table to json I have a large table of data that I would like to convert to json and am not sure if a tool like jq, mlr, or similar would be able to perform such a task without having to resort to my poor awk skills. Sample table: Balance_sheet for AAPL: 2023-09-30 2022-09-30 …

Total answers: 3

Awk- Compare Numbers from Two Files and write Differences in New File

Awk- Compare Numbers from Two Files and write Differences in New File I have two lists with item numbers and want to mark the difference between these lists by writing the numbers wich aren’t in both files in a new file. Both Files have the item number in column 2 and part ID in column …

Total answers: 4

find and replace specific string in multiple csv files

find and replace specific string in multiple csv files I have multiple csv files and the contents are in the following format: "TIMESTAMP",col2,col3,col4 "yyyy-mm-dd HH:mm",20,19,17 I want to replace – with / so that in the end I have: TIMESTAMP,col2,col3,col4 yyyy/mm/dd HH:mm,20,19,17 I used the following command to append the files but nothing is happening: …

Total answers: 4