Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

1
vote
3answers
34 views

awk to replace columns and print if condition statisfy

I have a file with below output Sending showtrans string ... Oldest redo log files necessary to restart Extract are: Redo Thread 1, Redo Log Sequence Number 29334, SCN 3364.4078507030 ...
5
votes
8answers
400 views

Generate two sequences of numbers separated by “|”

I'm using bash (CentOS 5) and looking to generate this output (I assume I could use seq or echo together maybe?): 1|1, 2|2, 3|3, .... 31|31, 32|32, 33|33, I googled seq examples for over two hours ...
0
votes
2answers
55 views

Find value in one column and print corresponding value from other one

I have text file with values as: 1 Peter 2 Paul I need a command/scipt that will take as a parameter value from the second column (e.g. Paul) and return the corresponding value from the first one ...
2
votes
5answers
139 views

How to make grep return value without comma [duplicate]

I want to extract a value from a json file so that I can process it and I try that using grep '"USDEUR" currs.json' | cut -d ':' -f 2 but it returns 0.918695, and the json file looks like this: { ...
1
vote
3answers
89 views

Compare two files with awk

I'm trying to compare two files and print the output if they match on some fields. File1.txt: bart:29482164591748 apu:29482164591748 smithers:68468468468464 lisa:68468468468464 ...
10
votes
8answers
308 views

sed in-place line deletion on full filesystem?

Due to an application bug as yet undiagnosed, I have several hundred servers with a full disk. There is one file that has been filled up with duplicate lines—not a log file, but a user environment ...
1
vote
2answers
66 views

Select filename with highest version number

highestVersion() { for TEST_PATH in `ls -a "$/TEMP"/*.flg` do echo " you are here" TEST_FILE=`basename "$TEST_PATH"` echo "$TEST_FILE" done } Below is the file ...
3
votes
1answer
128 views

How can I write data separately in many text files which contain the same fields?

I have a text file which contains around 9999999 lines. Here I'm pasting the few lines: 1874641047 Gazipur 1874646347 Jessore 1845105653 Chittagong 1845146123 Narayanganj 1845164162 Gazipur ...
5
votes
7answers
308 views

Remove lines from tab-delimited file with missing values

I have a large (~900MB) tab-delimited text file that I will be processing in a downstream program. I need to delete any line with a missing value. The correct number of columns are on each line (so ...
4
votes
3answers
168 views

How to replace text in a column

I have a huge file (more than 2 GB) where data is like below. 12,324,32342,E:fsdsf,23432,34534,45345,324 13,3224,342,E:werwefsdsf,23432,34534,45345,324 121,3244,33442,E:,23432,34534,45345,324 ...
1
vote
1answer
41 views

Don't run this sed when a string is matched?

I have this sed command for deleting numbers inside of tags: sed 's/\(<[^0-9>]*\)[0-9]*\([^0-9]*>\)/\1\2/g' But does anyone know how I can exclude certain strings from this? Now it would ...
3
votes
2answers
57 views

Replace only on the first matching line with sed

Using BSD sed (no GNU extensions), how can I perform an operation similar to the example provided below, but where instead of the line number, the replacement is performed on the first line in which a ...
0
votes
2answers
42 views

Remove both lines if column A values are repeated in next row

My input is like this: pak_c35079_g1_i1|m.14890 Pfam pak_c20797_g1_i1|m.3458 ProDom pak_c20797_g1_i1|m.3458 Pfam pak_c28265_g1_i3|m.9595 TIGRFAM pak_c28265_g1_i3|m.9595 ...
2
votes
2answers
25 views

How do I keep the lines with the highest number where a pattern is matched?

For example, if my file looks like this: string string1 string2 string4 string800 value2 value3 value5 value10 something18 something20 I want the output to be string800 value10 something20 ...
5
votes
3answers
240 views

egrep regular expression - same word in the beginning and end

I want to find all the lines that have the same word in the beginning and in the end of the line. For example: goodword fgdlakj 3t sfkl 43lk fkl goodword bad sfa;lk3t dgk;gs 34;kl ...
0
votes
1answer
33 views

arithmetic operation with columns in text file

I have a data file which consists of two columns. I need to perform arithmetic operation with these columns as follows; column_1=a(i) column_2=b(i) where i is the line number ...
1
vote
2answers
54 views

How to ONLY print the number that is being produced from du -sh /home?

I am new at unix systems and I wanted to know how to ONLY print the number that is being produced from: du -sh /home because if I execute that command it will print: 44M /home I only want the 44M ...
-2
votes
2answers
30 views

how to append a value into the empy text file

assume I have an empty text file, touch empty_file How can I insert a specific value into the first line of this empty_file?
1
vote
2answers
33 views

Find out most frequent strings in section of file

I have a file that looks like this: o99 ksad<tab>abcde $%!H$!(<tab>00 !sdaf as<tab>12 sarwa &!§! &% (where <tab> represents a real TAB character). For clarification: It ...
2
votes
5answers
69 views

How do I parse a file like this, and define the variables? [closed]

Example file: /Variable1=Value1/Variable2=Value Value Value/Variable3=Value3 Value3/ I want it to read the variables and set them. Meaning I would be able to type echo $Variable1 and get Value1 as ...
0
votes
2answers
43 views

Replace numbers in file1 with corresponding line in file2

I have a file that looks like this File 1 3 123456789 3 00000 2 123456789 2 abcde 1 4 abcdefgh The lines in the first column correlate with the line number of another ...
0
votes
2answers
31 views

Replace numbers in first section of file by result of calculation

I have a file that looks like this: 1 abcde 2 00 3 12 4 12 5 ghijkl 6 jsaslm 7 uawrns 8 abcde 9 \(%"!&/ 10 $!"$&/( 90 !§%/(// I want to ...
-1
votes
1answer
52 views

Grep/sed between two strings

I have this code at the moment cat -n rfile | sed -n '/"semantic_url":"/,/","/p' where rfile is a file with a lot of text. I am trying to extract everything between every "semantic_url":" ...
2
votes
2answers
212 views

Solaris using sequence generator at the beginning of each new line

I am new to shell scripting. I created a script that extracts data from a database and loads it to a csv file. I am using SunOS hstz1454 5.10 system. I am trying to do a sequence at the beginning of ...
3
votes
2answers
42 views

modify text file with only one number subject to constraints

I have a text file a.txt whose content is a number between 0 and 100. I need a single command which modifies a.txt by increasing by 10 the number, but under the constraint that the final result has to ...
2
votes
0answers
43 views

Text editor that allows for coloring of arbitrary text (and exporting thereof)?

I have a rather large backtrace, which is kind of difficult to read, so I thought I'd color the portions of the backtrace text for easier reading. (I thought, as a backtrace problem, this question is ...
4
votes
1answer
39 views

Display only duplicate lines, ignoring the first x spaces per line

I have a file with numbered lines. The numbers are taking up the first 7 spaces each line. I want to check the remainder of the line for duplicates and only output the duplicates. For example, my ...
4
votes
2answers
137 views

concatenate n lines with sed

Recently, I asked a question how to sort pairs of lines, and one of the answers suggested concatenating lines with sed, like this: cat file.txt | sed -n 'N;s/\n//;p' | sort -t";" -k43,43n | perl ...
2
votes
1answer
28 views

How can I selectively modify the lines in a file where the modifications depend on analyzing the select lines as a whole rather than individually [duplicate]

TL;DR I need to align the columns of the entries in fstab while ignoring the comments: /dev/foo /foo ext4 defaults 0 2 # comment line 1 /dev/bar /bar ext4 defaults 0 ...
1
vote
1answer
37 views

Extract fields of a line into shell variables

I have a few hundred lines like below in connRefused.log:- 2015-12-12 00:12:10,227 ERROR [Testing-KeepAlive-01] c.v.v.v.Connection [Connection.java : 001] failed to bind to ...
2
votes
1answer
71 views

Matching two main columns at the same time between files, and paste supplementary columns into the output file when those main columns match

I have 3 files, each with a unique number of columns, all tab-separated, but some columns are shared between the 3 files. It's the shared columns between the 3 files that I want to use to create some ...
3
votes
1answer
204 views

Using SED to cut after 7th character of each line

Just trying to cut any characters after the 7th on each line of a text. I initially tried this: sed 's/(.{7}).*/\1/' TestText.txt But got this response: sed: 1: "s/(.{7}).*/\1/": \1 not defined ...
-5
votes
1answer
31 views

in a list, delete all the words which do not start with a capital letter

Given a list of words (one per line) list1.txt I want to produce an output containing only the words which start with a capital letter. Any special option for grep?
0
votes
4answers
40 views

How to remove a first character of that particular sentences from a list of output [duplicate]

grep /var/log /etc/rsyslog.conf | awk '{print $2}' Output: /var/log/messages /var/log/secure -/var/log/maillog /var/log/cron -/var/log/spooler /var/log/boot.log I want the result to be: ...
14
votes
1answer
714 views

How to “grep” for line length *not* in a given range?

NOTE: This question is the complement of this Q&A: How to "grep" for line length in a given range? How can we grep for lines that have less than 8 or more than 63 characters, none ...
4
votes
1answer
55 views

How to use Awk to format numbers with a thousands separator

Can anyone tell me how to use the awk command for this statement "the number will contain commas after every three digits. For example, 100000000 will become 100,000,000." I know how to use sed ...
4
votes
3answers
154 views

check if a string has a character more than once

The title actually almost explains it all. I would like to check if a string contains a letter (not a specific letter, really any letter) more than once. for example: user: test.sh this list ...
2
votes
2answers
58 views

Combine multiline to one line with proper format

I have a file say FILE1.txt contains below data:- A B C D E F G H I J K L I need the output in another file as FILE2 as:- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L' Note:- New ...
2
votes
2answers
63 views

How to find unique word in a single line

I have a string which is something like 50003 50003 50003 50001 this I get after processing into another file which is stored into a variable. now i want from that variable unique words. Like 50003 ...
3
votes
4answers
213 views

finding all the words in a text file appearing in another text file

Suppose I have two files a.txt and b.txt. I want to find all the words in a.txt which appear in b.txt. Is there a specific command to do that?
0
votes
1answer
31 views

Make new line above last line and add something there

Like a reverse of awk 'NR==2 {print ""} 1 which adds a new line under the first and prints whatever there. I can't replace the number after NR== with a fixed value because I want to be able to do this ...
3
votes
2answers
43 views

How to use grep to return lines with an hexadecimal number in a given range?

If I have, say: blah;PC=1234abcd PC=4444bbcd;blah PC=0000abcd;;foo PC=1234abff How do I grep for lines with PC values in a given range, say 1234ab00 to 1234b0ff. The - range option seems to only ...
3
votes
3answers
78 views

Print all matching lines and the previous unindented line

For example, lets say I want to find all lines with 'matching' and the previous unindented lines in this text. Container 1 some text some text matching text some text Container 2 some ...
0
votes
0answers
34 views

copying a set of lines into new file

I have a text file with 100,000 lines or more. I want to copy specific lines from the text file into a new file using: sed -n '1,1000p;1000q' orig-data-file > new-file However, I want to create ...
1
vote
2answers
41 views

Parsing with awk by modifying the field and record separators

I have a file which is as follows: ------------------------------------------------------------------------------------------------------------------------------------------------------------------ ...
7
votes
5answers
1k views

How to find lines containing more than 100 characters and contains “if”?

So, probably I should use grep for this. As long as I need recursive search I should use grep -r. But then I don't know what should I do next ;) How can I do that?
2
votes
1answer
168 views

GREP exclude first 11 values

I have a massive log file that I need to filter. In this log, I want to display all logs that contain the string dns and I want see them just once. i.e from this: Dec 9 07:24:02 94.15.218.140 ...
1
vote
3answers
60 views

How to sort blocks of lines with a specific line from the block?

I have a file with the data like this BEGIN hello2 5 world1 END BEGIN hello4 2 world5 END BEGIN hello6 4 END I want to sort the lines in the following manner based on the number inside the block. ...
0
votes
2answers
23 views

Creating one file from another based on search terms

How can I create a file that contains everything after and including a particular search term from another file in the terminal? Example: Original file content: foo, bar, baz, qux Search term: baz ...
1
vote
3answers
43 views

combine selected column multi file

I have multiple files (~15), each with multi column data (tab seperated). For example: File1 aa1 399 1815 aa2 1908 4064 aa3 4523 5656 File2 bb1 5304317 5305057 bb2 ...