Skip to main content

All Questions

Tagged with
6 votes
3 answers
644 views

awk: sort by first column then second; output unique 1st column once but all 2nd column

I have a two-column file that you can create as follows cat > twocol << EOF 007 03 001 03 003 01 137 12 001 11 002 01 002 02 002 03 001 02 002 04 137 94 010 21 001 01 EOF The resultant file, ...
bballdave025's user avatar
3 votes
7 answers
434 views

How can I print the longest sequence of lines featuring numbers smaller than a threshold?

I am learning Perl, but I don't know how to solve this problem. I have a .txt file of the following form: 1 16.3346384 2 11.43483 3 1.19819 4 1.1113829 5 1.0953443 6 1.9458343 7 1.345645 8 1....
69 420 1970's user avatar
2 votes
4 answers
211 views

Parse text file add semicolons before and after numbers; join all other words that are before/ between numbers with hyphens

I have a text file with accounts like: Input Sample Paid 100 15/02/2022 3000 recd 50 15/02/2022 nelur trip 3050 PAID 80 25/03/2022 Adjusted towards trip 3130 14 PAID 50 26/03/2022 Given to Nate Cash (...
tgkprog's user avatar
  • 249
0 votes
2 answers
308 views

perl: replace a string with variable containing new lines (line breaks)

I want to make edits containing meta characters. Here https://stackoverflow.com/questions/29613304/is-it-possible-to-escape-regex-metacharacters-reliably-with-sed one of solutions is via perl with s\Q ...
Martian2020's user avatar
  • 1,219
0 votes
4 answers
658 views

Remove hostnames from URL with sed/awk

I got lists of urls with different domains and I want the hostname removed with sed, awk or something similar and only keep the path. There are no urls with port or username@password in it. input: ...
pwrsheller's user avatar
-1 votes
3 answers
132 views

How to replace the contents of out.txt with in.txt in a third file?

I have three files, main.txt, out.txt and in.txt. I want to replace every occurrence of the contents of out.txt in main.txt with the contents of in.txt. Both out.txt and in.txt may contain multiple ...
Roger Bosman's user avatar
0 votes
5 answers
118 views

Remove three lines from file until a match

982 01:25:09,473 --> 01:25:10,978 Stay with me. 983 01:25:09,473 --> 01:25:10,978 Stay with me. 984 01:25:15,390 --> 01:25:18,484 ( MAJESTIC MUSIC ) I want to delete three lines below 984 (...
Jakub Fiala's user avatar
1 vote
6 answers
935 views

Find and replace a multi line text file in another multi line text file

I fought with it for so long but I am now completely out of ideas. Maybe someone here will be able to help me. Here is what I want to achieve: file_1.txt: # Some comment some_variable="test" ...
Peksio's user avatar
  • 121
1 vote
2 answers
222 views

Remove all characters from string, except specific multibyte range

How would one use sed or another tool to remove all characters except a specific multibyte range? For instance, the range \xd8\xa0 - \xd9\x8a covers Arabic characters encoded in UTF-8. This was my ...
dotancohen's user avatar
  • 16.1k
3 votes
4 answers
584 views

sed + add string on the beginning of line but ignore if already exist [duplicate]

here is example how to add string on the beginning of line when match the UUID number in fstab sed -e "/UUID=953b1921-ac73-4b7b-abaf-ff983b0fce8a/ s/^/###FAULTY_DISK###/" -i /etc/fstab and ...
yael's user avatar
  • 13.4k
6 votes
8 answers
599 views

Make change operations on substring only

In a file that has any garbled text before and after a section that is marked by patterns START and END (specific strings that occur only once each and in the correct order and on the same line). I ...
FelixJN's user avatar
  • 13.7k
0 votes
1 answer
55 views

match column1-5 in both files and print matching column1-5 along with column6&7 of file1 and column6 of file2

want to match column 1-5 in 2 files and print column1-5 along with column 6&7 from file1 and column6 from file2. Non-matching rows from both file should also get printed with NA value in non-...
rij's user avatar
  • 25
1 vote
2 answers
296 views

extract fields based on a string (partial and exact)

Expertos: I want to extract fields based on a string (partial and exact). In some rows these fields are moved one or two columns, so I can't specify the column (which is the extent of my knowledge). I ...
Age87's user avatar
  • 559
0 votes
4 answers
50 views

Replace TAGS in FileB with VALUE from FileA

I am looking for some assistance in perl, please. I have most of the code built, but I am finding one part particularly challenging. If FileA: tag1=value1 tag2=value2 and FileB: value1=<tag1> ...
Dragon's user avatar
  • 1
3 votes
2 answers
334 views

Squash file with key-value records to CSV [duplicate]

I want to write a data parser script. The example data is: name: John Doe description: AM email: [email protected] lastLogon: 999999999999999 status: active name: Jane Doe description: HR email: [email protected] ...
annahri's user avatar
  • 2,075

15 30 50 per page
1
2 3 4 5
23