Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

0
votes
2answers
41 views

How to find and replace only a particular word (which is at the end of the file) using shell command?

File1: Dms 01.01.2015 feeder1 6kv close at 04:30 Updated Dms 01.01.2015 feeder1 6kv open at 06:20 Updated Dms 04.02.2015 feeder10 6kv close at 17:23 Updated Dms 04.02.2015 feeder12 6kv ...
0
votes
1answer
33 views

Bash: How to append a range of lines from a file to another

Let's say I have file contents similar to the following (fileA): lorem.ipsum=dolor sit amet. donec.non.nibh=ut tortor nam.mattis.lacus=et rhoncus sodales get.placerat=neque fringilla. What are the ...
0
votes
2answers
58 views

Find all characters “[1-777])” at the beginning of the line

Pseudocommand perl -pe 'g/^[1-777])/g' data.txt where I try to all numbers at the beginning of a line with ")" following them etc 1), 67) and 777). Data where all question numbers should (etc 1), ...
1
vote
2answers
48 views

Match beginning of a line with something there?

I want to match the beginning of lines where the line contains something. Command in Perl/Sed 's/^.?/\section{}/g' but the problem here is that it replaces also the first character of sentences. ...
0
votes
0answers
15 views

Why this exclusion not working for long sentences? [migrated]

Command perl -ne 'print unless /.[240,]/' input.txt > output.txt which includes some sentences which are longer than 240 letters. Why? Example data Development of World Funny Society ...
5
votes
2answers
324 views

Read multiple lines from text files in bash

When I am shell scripting, the majority of what I am doing is wrapping the I/O of other modules in python, matlab, etc. To do so, I usually use text files or something of that nature with the ...
4
votes
1answer
35 views

Gedit displays text, but cat tells a different story

I am trying to sort a dictionary from Grady Ward's Moby and have encountered a bit of a problem. When I open it in gedit, I get: abaca×N abaciscus×N abacist×N aback×v abacli×p Abaco×N abactinal×A ...
0
votes
1answer
31 views

Filter out combination options in lines

Data Life by cerebral flow is coming to:---1) Prolonged jumping rate---2) Small holiday course---3) Hello this world---4) Dance rock coffee---5) Therapy unproven---Choose right ...
1
vote
2answers
45 views

Print log lines excluding previously-repetitive lines?

If I had a log file looking like this: A A B C C C A B B I would like to output (remove the immediately-successive duplicates): A B C A B How do I do this?
14
votes
9answers
575 views

Filter file by line number

Given a file L with one non-negative integer per line and text file F, what would be a fast way to keep only those lines in F, whose line number appears in file L? Example: $ cat L.txt 1 3 $ cat ...
1
vote
1answer
54 views

How to write data one by one from tmp files to the final output file using for loop?

I have two tmp files named tmp1 and tmp2 which contains some lines. tmp1 file, 1c\ datafile no. 23 2c\ datafile is ok tmp2 file, 3c\ datafile no. 24 4c\ datafile is ok I have a ...
1
vote
4answers
88 views

How to insert lines from one file to another file using shell commands?

I want to write 8 lines from file1 at the beginning of file2. My file1 contains the following lines: $BQ { VOL @home } database daba relation tcdeatid copy 1 { ...
1
vote
3answers
45 views

Search word preceded by Name in Sed

This thread is motivated by the arithmetic command found in the link of this thread here in Sed. So I would like to do backward arithmetic in Sed. Data Mikael symptom David symptom hello symptom ...
4
votes
2answers
99 views

Replace 1st with 1), 2nd with 2), … in GNU Sed

Pseudocode which is a continuation from this answer gsed 's/|/1)/g' 's/|/2)/2g' 's/|/3)/3g' 's/|/5)/4g' 's/|/5)/5g' <input.csv >output.csv which is of course not working. I am interested in ...
1
vote
0answers
20 views

Converting a raw print data stream containing PCL commands to PDF

I have a program that sends raw print data through samba to typically PCL compatible printers. The program is written so basic PCL commands control how it prints. When sending it to the printer it ...
2
votes
3answers
83 views

Format column-based text file into tree structure using bash

Is there a Unix/Linux command that can turn this: AMERICA USA NEW_YORK AB-100 AMERICA USA NEW_YORK VF-200 AMERICA USA NEW_YORK XY-243 AMERICA USA LOS_ANGELES UH-198 AMERICA CANADA TORONTO ...
4
votes
5answers
364 views

How can I replace all semicolons after 1st one?

This problem is related to my attempt to import questions and their answers in a Excel file into .txt -file which Anki flashcard program handles as described here. I cannot have more than 2 fields so ...
0
votes
1answer
28 views

Delete lines in a txt file by taking patterns from another file [duplicate]

I have two txt files : file1.txt: user1@domain.fr user2@domain.fr user3@domain.fr user4@domain.fr ... file2.txt: user2@domain.fr user4@domain.fr fileIwouldhave.txt: ...
0
votes
1answer
43 views

Delete duplicate entries in a text file [duplicate]

I created a txt file using two requests, one LDAP and one SQL. Results of the two requests are stored in the same txt file. The txt file looks like this : user1@domain.fr user2@domain.fr ...
1
vote
3answers
59 views

Sed Replace at a specific group of positions

I have a sample input file as below: Apple Orange Gold Silver Spoon Apple Orange Gold Apple Apple Orange Apple Orange Mango Gold ...
1
vote
2answers
43 views

add ordering number to specific text

Is there any way to add a number into a specific text? On my text file: <a href="http://localhost/file1.txt">file </a> <a href="http://localhost/file2.txt">file </a> <a ...
2
votes
4answers
168 views

Removing every line that is not a sequence of 7 numbers

I have a text file like this: 229;39;45;11;21;33;13 230;56;44;41;40;08;53 231;16;59;27;42;44;36 232;29;19;41;22;37;59 233;45;03;24;36;07;32 SP;SP;SP;;;; 234;15;45;54;25;42;41 235;29;41;55;02;31;22 ...
3
votes
2answers
72 views

shell script to extract between characters

I would like to extract a user name from the file between the keywords "/" and "NET" like below. How can I do so with programs like awk, sed or cut. from: audit: command=true ...
0
votes
2answers
48 views

Count frequency of specific numbers in a text file of scientific notations

Background I have a text file, named blood_conc.txt as shown: 0, 0, 0, 0, 0, 0, 0, 1.32006590271e-05, 1.990014992001e-05, 1.504668143682e-05, 2.176900659261e-06, 7.673488970859e-06, ...
3
votes
4answers
205 views

Extract paragraph separated with *** using AWK

I have a file like below: blablabla blablabla *** thingsIwantToRead1 thingsIwantToRead2 thingsIwantToRead3 blablabla blablabla I want to extract the paragraph with thingsIwantToRead. When I had to ...
2
votes
2answers
35 views

One-liner to sort and uniq two outputs

I'm currently doing this to sort and uniq the output of two different commands: tshark -r sample.pcap -T fields -e eth.src -e ip.src > hello tshark -r sample.pcap -T fields -e eth.dst -e ip.dst ...
0
votes
1answer
52 views

Get a CSV file containing names of files within a directory?

I am trying to figure out how to export the names of the files I have in a directory to be saved in a CSV file that I can edit in Excel. The directory looks like this: $ ls Sample_38_41_1_A01 ...
3
votes
4answers
77 views

To remove newlines after empty line

Data 4. Alendronic acid A. Antiosteoporotic agent. B. Inhibit osteoclast formation and function by inhibiting FPPS enzyme, so increase bone mass. C. Osteoporosis in combination with vitamin D. ...
-2
votes
1answer
53 views

Remove everything else after this mark?

Data C. Induction anesthesia, muscle relaxant, anxiolytics, 1st line sleeping disorder (but short time in market). \part{Theoretical Questions} Lorem Code cat ...
-2
votes
3answers
52 views

Removing column in field seperated file using scripting

The files is seperated by | pipe symbol myfile.txt Hello|how|are|you|hope|you|are|doing|fine Lilly|jasmine|rose|sunflower|nightfire|flowers I want to remove columns greater than 3. I want result ...
3
votes
7answers
145 views

Insert a word in the first line of the file

Input: firstline secondline thirdline ...some magic happens here... :) Output: insertedtextfirstline secondline thirdline Question: How can I insert the insertedtext to the start of the first ...
2
votes
2answers
50 views

Inserting into middle of a string using sed

I'm trying to insert a string into multiple lines using sed, but i don't get the desired result I have this: <p begin="540960420t" end="600189590t" xml:id="subtitle8">-Some ...
2
votes
5answers
131 views

Get Comma Delimited List of Initials of Items in Directory?

How can I generate a comma-delimited, case-insensitive list of the first characters of the names of the files and directories in a directory, excluding initial "." items, without duplicates? I don't ...
3
votes
3answers
183 views

How to use sed command to modify a file's entry line by line in shell script?

This is my file1: #$BQ #{ VOL @home } #database daba #relation tcdeatid #copy 1 #{ version 0 } #opendb #clear #.lruno := 72 #.infno := 1 #.tid.noel := 101 #.tid.info ...
0
votes
0answers
16 views

Searching text data in Hebrew, Arabic or Aramaic

How can I search for a (sub-)string in a database that has several languages, including Hebrew? I am assuming that the text being right-to-left is a question of the presentation, but the logical ...
4
votes
3answers
96 views

Convert /proc/cpuinfo to a JSON in linux bash

I'd like to convert the entire entry of a cat /proc/cpuinfo to a JSON of "key" : "value". Is this possible? I tried to explode the string using \n in hopes that I could get each line and then I could ...
2
votes
4answers
66 views

remove the content from the beginning to the first blank line

I'm trying to remove the content from the beginning of the text to the first blank line. --($:~)-- cat example.txt pedro pablo juan francisco emiliano martin So, I would delete: pedro pablo ...
4
votes
5answers
89 views

Multiline Text Processing : Editing sshd_config

I have multiple blocks at the end of my sshd_config files like theses: Match User FOO ChrootDirectory /srv/www/FOO AllowTCPForwarding no X11Forwarding no ForceCommand internal-sftp ...
-1
votes
1answer
27 views

Count of Lines within a Range

I'm trying to do a count of all the values (numeric) in the third column of a file that fall within a specific range of numbers. I've found the min and max but have no idea how to do the count now. ...
2
votes
6answers
160 views

grep with continuation lines

How can I grep/awk/sed a file looking for some pattern, and print the entire line (including continuation lines if the matched line ends with \? File foo.txt contains: something whatever thisXXX ...
4
votes
2answers
141 views

Cat file1 into file2 after specific pattern match

I have file1 & file2, I want to cat file1 into file2 after match of 22 pattern. Can I do it with cat or I need to go for awk or sed file1 aa bb cc file2 11 22 33 44 Resultant file2 11 ...
0
votes
3answers
54 views

How to sort/reformat text information in a file?

I have a file (called customers) with information that needs to be sorted; example: qweasd,asdqwd@asd.org,256.62394383 qweasdczasd,asdghjghqwd@assssd.org,256.62394383 ...
2
votes
3answers
51 views

Delete lines between 2 strings in Solaris

I want to delete all the line between two patterns using basic awk or sed. foo.txt : ---------------------------------------------------------------------- Cap in MB line 2 line 3 line 4 line 5 ...
2
votes
2answers
56 views

Getting Group Names for List of Users

I have a text files with a list of users formatted like: name1 name2 name3 ... Calling the command groups gives the primary group name for that user. ex: bash$ groups name1 name1: ...
-3
votes
1answer
66 views

AWK sum every two rows

I want to sum two rows until end of file: 1 2 3 4 0 1 2 3 0 4 5 6 2 3 5 6 Output should be 1 3 5 7 2 7 10 12 I have tried the following, but it only works for the 1st row awk ...
16
votes
15answers
1k views

How to find line with least characters

I am writing a shell script, using any general UNIX commands. I have to retrieve the line that has the least characters (whitespace included). There can be up to around 20 lines. I know I can use ...
4
votes
6answers
347 views

sed command to swap characters

My input file layout is: mm/dd/yyyy,hh:mm,other fields I need to format it as: yyyy-mm-dd hh:mm:00,other fields sample input: 01/02/1998,09:30,0.4571,0.4613,0.4529,0.4592,6042175 ...
4
votes
4answers
300 views

Merge two files

I have this file1.txt deiauk 9 kespaul 8 luktol 7 titkur 6 and other file2.txt kespaul b deiauk a And I want to merge both files in one by first value, so my result should be deiauk 9 a ...
2
votes
3answers
227 views

How to sort data in the file using script?

I have a file logs.txt with numbers which repeat: 1 QWE 1 ASD 1 QWE 1 QWE 1 QWE 1 qwe 12 22 qwe 2 aaa 2 vcc 2 xxx 4 asa 44 qwe 4 gfd 4 bcx 5 6 kuy 7 76 lol 5 4 ggg 23 ...
2
votes
1answer
31 views

Trouble with horizontial merge of csv files under Cygwin

I have two csv files: test1.csv 1 2 3 4 test2.csv 6 7 8 9 I want to horizontally merge these two files. To do this I use paste -d , test1.csv test2.csv > paste.csv If I open this file in ...