Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

0
votes
1answer
41 views

insert comma after the last letter

I use a txt file, and I need to convert it in csv file Saint Petersburg 0 10 0.1 - N Moscow - 9 0 - N Novgorod 0 7 1 30 Y In ...
3
votes
3answers
304 views

Take the first column from 2 files and write it to a 3rd file

Suppose I have 2 Files, ABC.txt & PQR.txt with the data shown below as an example: ABC.txt: ABC DEF PQR.txt: PQR XYZ I want to grep column 1 from both files and write into a third text ...
3
votes
2answers
236 views

random permutation of lines of text

If I have a file with following content: 0001 0002 0003 0004 0132 0137 0138 0141 How can I get a random permutation of them in bash?
8
votes
2answers
264 views

How can I delete all text between nested curly brackets in a multiline text file?

This question comes from How can I delete all text between curly brackets in a multiline text file? (just the same, but without the requirements for nesting). Example: This is { {the multiline ...
3
votes
3answers
255 views

How can I delete all text between curly brackets in a multiline text file?

Example: This is { the multiline text file } that wants { to be changed } anyway. Should become: This is that wants anyway. I have found some similar threads in the forum, but they don't seem ...
0
votes
1answer
38 views

Macbook System Profiler formatted

I want to format the output generated from macbook terminal command system_profiler and transpose the row values to columns under the same Application. Here's a snippet of the file: Firefox: ...
2
votes
5answers
149 views

Re-order text on each line in a file

I'm processing a log file and I need reorder each line (not sort). The log file looks like this: 11-06-2014 - 10:49:06PM lat = 41.858657; lon = -91.345142 11-06-2014 - 10:49:49PM lat = ...
3
votes
6answers
121 views

how can I use sed to replace the lists that begins with (*) in a file

Using sed how can I replace the lines that start with a star and replace it with numbers starting from 1? I need to replace the (*) in the fist of a list with numbers using sed for example > this ...
1
vote
3answers
48 views

How do I analyze report type of data in Bash?

What is the best way to read the following data in Bash? For example if the data is like a ls -l then I could read line by line and I have all the detail of a file within a line. In this case I have ...
2
votes
4answers
141 views

Concatenate different fields with different seperator

I have a tab delimited file like this: chr1 53736473 54175786 chr1 56861276 56876438 chr1 57512145 57512200 I want to concatenate the three fields result like this: ...
3
votes
4answers
256 views

Club together N consecutive line in shell?

Let say I have a text file in this format field1a field2a field3a field1b field2b field3b I want to club 3 (or in general case N) consecutive lines, how will I do it with sed or other command line ...
2
votes
2answers
61 views

Parse several thousand lines of txt into lines and columns

The file at hand lists names, credentials, roles, and privileges for thousands of users. It was passed onto me as .xls but the lines and columns are not arranged in proper form. I have reformated ...
6
votes
8answers
732 views

How do I construct a list with numbers like this?

How do I construct a list like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Where I run command 15 or something. Or if I specify 100 it would make it with 100 numbers or 10000 and it would make it ...
0
votes
1answer
37 views

Replacing code between two JavaScript comments

I need to set a value of JavaScript variable from bash. Variable lives in index.html file and I'd like to use unix SED command to do that. Inside index.html I have it lake this: <script> ...
1
vote
1answer
30 views

convert row into column based on particular key

I have file like Below. But header are in different line the header Values are printed in down to the hear. I want all the header in single row & value to the Particular header to be print to ...
6
votes
4answers
583 views

Modify a file without creating another file

Is there a way to modify a file without writing the contents to other file, without sed and awk? For example, $ cat test.txt aaa aaa bbb ccc ddd Replacing using sed with -i option, sed -i ...
5
votes
2answers
313 views

delete a line if same line exists in the previous line

I want to remove lines which exist already in the previous line from the command line in UNIX. I have the following data in a file. <xref ...
2
votes
6answers
89 views

Getting the matched word exactly

I have looked through a number of question but they do not satisfactorily reply to my question. I need to print words that match the pattern exactly not the lines containing that word. For example: ...
1
vote
1answer
39 views

Need to use grep and sort for matching records and display Y and N

Input file (contain column 1 with repeat value in number and second column may contain voice,email, tel, voice mail): 123,voice 123, tel 324,voice mail 345,email 123,email Output file with headers ...
1
vote
2answers
62 views

Add certain words to a file

I am using this code to read the line number 2 from files has the same name and included in folders (the name of those folders included in list.txt): #!/bin/bash in=/au/cl/tr/129/ inlist=/1/2/3 ...
3
votes
3answers
116 views

Delta of numbers in file

On our server a cronjob has logged a count of files in a shared directory. The log is of the form: 2003-07-03T16:05 279 2003-07-03T16:10 283 2003-07-03T16:15 282 By now this file has far over a ...
0
votes
1answer
30 views

Need to compare the two files and print all the columns then missing display as NA, then join another file [duplicate]

File 1: 123, 234 345, 789 678, 900 File 2 123, abc 345, dnc output (all columns in file1 and missing value in file two as NA): 123,234,abc 345,789,dnc 678,900,NA Output file add with another ...
1
vote
3answers
65 views

using awk command to compare the two files and print all the columns then missing display as NA

File 1: 123, 234 345, 789 678, 900 File 2 123, abc 345, dnc Desired output (all columns in file1 and missing value in file two as NA): 123,234,abc 345,789,dnc 678,900,NA
0
votes
1answer
56 views

script to read certain key words in a document

I have a list of 50 folders. Inside every folder I have a text file contain key words and this file has the same name in all the folders but it has different values. How can a script read a certain ...
7
votes
7answers
448 views

How can I double the newlines in an output stream

When I have an output stream: a b c d e How can I double the newlines: a b c d e
8
votes
4answers
326 views

Remove duplicate lines from a file that contains a timestamp

This question/answer has some good solutions for deleting identical lines in a file, but won't work in my case since the otherwise duplicate lines have a timestamp. Is it possible to tell awk to ...
-1
votes
3answers
54 views

Look for numbers that is supposed to exist, but doesn't

I have a long list of numbers. Is there any way I could display the numbers that doesn't exist? In this case it would be 2 and 4 1 3 5 6 The list is in a text file. To clarify, I just have one ...
-1
votes
4answers
78 views

how to substitute some lines of one file according to the line's content [closed]

I have a file like this (this is a sample, the file contains more lines like these): first line sss case-2-hello-world other words second line other words third line sss case-1-love-you other words ...
2
votes
2answers
94 views

How to capture the port number from this `lsof -F` output using awk (or something better)?

I've got output coming from lsof -F that looks like this: p7646 g7646 R8300 csocat u1000 Labe f3 au l tIPv4 G0x80002;0x0 d640391 o0t0 PTCP n*:51352 TST=LISTEN TQR=0 TQS=0 I am trying to capture the ...
2
votes
4answers
74 views

Merging Two Files with Difference only

I have two files. file1 contains text as follows: #This Data written by the platform Team id=kingDB file2 contains the text as follows: #This Data written by the platform Team id=kiteDB,mangoDB ...
0
votes
3answers
83 views

How do I search a file for a string then use it as a variable?

I have an XML file that looks like this: <id>456</id> <root> <value>1</value> <intNum>2</intNum> </root> <root> <eulav>1</eulav> ...
0
votes
2answers
73 views

Match a whole word (IP address) using `sed`

I have the following line style in a file: 1.2.3.4 1.2.3.4a 1.2.3.45 iaa1.2.3.4ad 11.2.3.4a a1.2.3.4 1.2.3.4> <1.2.3.4> <"1.2.3.4"> 1.2.3.4 hostname I want to replace all the ip ...
1
vote
1answer
35 views

Find string in text file and execute a script depending of the result

I have a file (Data.txt) with something like this: A=1234597890 B=192.168.1.1 sometimes B goes first and sometimes only A or B. So, If I find: A, Print A content and execute A script B, ...
1
vote
2answers
53 views

Print only the second field of the second line

I have to extract from the command hcitool dev only the mac address of the BT dongle. Output of hcitool dev is Devices: hci0 xx:xx:xx:xx:xx:xx I write this output on a file and try to get the ...
1
vote
1answer
35 views

Changing text in text file [duplicate]

Is there a command line way to change text in the file? Like say I would like to change all strings "lukuunottamatta" to the form "lukuun ottamatta" and "Lukuunottamatta" to the form "Lukuun ...
1
vote
1answer
44 views

How to nest global matches with sed?

If I do: sed 's/match/replace/g' I know that sed will substitute replace for every occurrence of match on a line. But what if...? echo "match <please dont match this?>" | sed ...
1
vote
3answers
88 views

Find and delete duplicate txt files

I have a folder with around 300 text files, is there any command that reads every every file indivdually and deletes the duplicate files? I mean the content and not the file names.
4
votes
4answers
281 views

How do I show the numeric character sequence of a string?

Is there a command either standalone or in vi or similar (can be gui) that will show me the numeric sequence of a string? Input: The cat hopped in a box. Output: T h e c a t h o p p e d ...
3
votes
5answers
127 views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
0
votes
0answers
22 views

Change encoding of a text file in-place: iconv alternative? [duplicate]

Apparently, iconv is unable to use the same file as input and output file. Other tools, e.g. sed, have an -i switch that allows "updating" a file in-place. (Under the hood, temporary files are ...
3
votes
3answers
296 views

Split the lines of a text file into separate files

I have a text file that looks something like this: foo bar zip rar tar I need to use a bash script on OSX to make a new text file after every new line like this: cat text1.txt foo cat text2.txt ...
2
votes
1answer
51 views

Extend grep to find a match after the first match

I have a long list of strings separated by newlines and each section separated by a string starting with ~ (there are no other ~ in the file). I want to extend grep to find the ~ text right below the ...
0
votes
1answer
23 views

transpose columns to rows in a spreadsheet [duplicate]

I have a spreadsheet has one column as the following: column A 1 a 2 b 3 c 4 d 5 e I want to ...
4
votes
4answers
345 views

How do I remove every number that's surrounded by <>

I have tried this sed -i '' 's/[0-9]*<>/g' But it didn't work. Example file: <Number1> </Number8> output: <Number> </Number>
4
votes
2answers
364 views

How do I populate end tags using sed, awk or any other command?

I have a txt file that looks like this: <sss>ss< or <firstword>anotherword< I want it to look like this <sss>ss</sss> or ...
1
vote
1answer
73 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
1
vote
1answer
76 views

Process Files to create a new file

I have a file1 which contains comma separated values (timein/timeout in military time format eg 0800, 0900, 1300). For each line of File 1 contains timein/timeout for each day. Sample File 1: Name, ...
-5
votes
1answer
103 views

Extract multiple lines from text file [closed]

Source : ! hostname RTR-1 ! boot-start-marker boot-end-marker ! logging buffered 64000 informational no logging console ! interface FastEthernet0/0 description LAN ip address 172.16.29.250 ...
2
votes
2answers
216 views

How can I remove lines matching foo but not matching bar?

Assume I want to remove the 2nd and 3rd, but not the 4th line in the following file (those which match foo but do not match bar), can I easily do this with e.g. sed? text foo some more text even more ...
0
votes
1answer
85 views

How to update files based on another file

I have 4 csv files and I want to update set of three based on values in the other one. The first 2 files (file_1 and file_2) contains names and their numerical ids. The third file (file_3) contains ...