Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

1
vote
4answers
38 views

rewritting text with automatic change with other file

I am trying to rewrite a file text, "main.txt" with changes from "changes.txt". The main.txt file is like this: word_1 genre_A word_2 genre_A word_3 genre_B word_4 genre_C word_5 genre_A And the ...
3
votes
3answers
10k views

Why grep doesn't show me the matching word until the next space?

I have a temp file, and I want to grep the only word that matches the pattern instead of whole word. i tried grep -o <pattern> file but its not giving me desired output Input xi29 vddf vss ...
2
votes
3answers
231 views

Append data of multiple files to new file separated by a line

I have more than a hundred firewall rules for many different customers in discrete files in a folder. Suppose the filenames are: 1.wawa.com_firewall_rule 2.newa.com_firewall_rule Each file ...
1
vote
1answer
41 views

Extracting from Logs

Actual logs are: 2016-06-19 22:08:09 [213917] 1bEgCe-000tZR-E9 ** saadia@aol.com (fahad@manakintextiles.com) <fahad@manakintextiles.com> F=<james@designplus.com> P=<james@designplus....
1
vote
1answer
44 views

Better way to apply formula to specific column of inputfile, and pass-through all other columns as-is

I regularly need to apply simple formulas to input data give in textual tabular form. In the beginning, I wrote specific little functions for each use-case. Then I re-factored the "common code" into ...
6
votes
4answers
630 views

I need to find all users home directories listed using grep from /etc/passwd

I have a question similar to another one on this site where the individual had to find a list of all users using grep or awk from /etc/passwd. That worked for me but I've tried translating it to find ...
4
votes
2answers
82 views

How Do I Remove Duplicate Words With Suffixes?

How do I compare a list of unsorted words of variable length and remove duplicate words that have a suffix? Example word list: iron curl curled railroad curler ...
0
votes
0answers
25 views

How to extract a search string from a line in AIX? [on hold]

How can I extract a string from a line looking for a pattern? For example: [6/25/16 19:13:10:364 ART] 0000300d SystemOut O INFO [WebContainer : 190] trip.c2c2 (Custom1344449048133....
6
votes
1answer
125 views

ANSI code translator

Is there any tool that translates text with ANSI code to text-like output? tput cap names or the like? Reason for the inquiry is that I would like to use script or the like and view the resulting ...
1
vote
3answers
53 views

Substitute a column i text file with incrementing numbers

I need to do something very similar to this Replace string with sequential index, but I don't need to add a number to a column, but substitute a whole column with incrementing numbers. Like this: 0 ...
0
votes
2answers
31 views

How to extract string between Nth and Mth occurrences of a pattern?

I have a file path.txt with the path to a file(say a txt file): /Folder/F1/F2/F3/F4/.../Fn/abc.txt I want to extract the path i.e the string from beginning to the last occurrence of / (since the ...
1
vote
3answers
72 views

Generate Sequence number for each line at the end .. modified t he post can someone help&suggest on this

I am new to linux I have got this query sed '/./=' abc.txt| sed '/./N; s/\n/, /' >> as.dat source file has 3 rows like below a b c When use the following command it gives me result like ...
2
votes
2answers
42 views

Command to print content before a symbol (last character in a line)

Let's consider I have 3 files: abc_def_12345.zip abc_123.zip abc_def_ghi_3432.zip I want to print only the characters before the last underscore(_) The expected output is: abc_def abc abc_def_ghi
0
votes
1answer
56 views

problem with sed inside sed

I am trying to parse a string inside a sed command but I am getting errors. sed -e "/pd begin $(echo 3:1I:1:1|sed 0,/:/{s/:/' '/})",/pd end $(echo 3:1I:1:1|sed 0,/:/{s/:/' '/})/p /tmp/hp-raid-data-...
0
votes
2answers
45 views

How to cut fasta sequence at specific numbers and generate ORFs

I have a file as shown below: CDS join(36..56,37..67) CDS 36..183 CDS 457..565 CDS join(505..519,521..596) CDS join(577..591,725.....
4
votes
2answers
49 views

Compose string of IPs using bash command line

I have a command that returns the following: id1="172" id2="17" id3="136" id4="5" id5="0" /> id1="172" id2="17" id3="128" id4="2" id5="0" /> id1="172" id2="17" id3="128" id4="4" id5="0" />...
3
votes
5answers
286 views

Add space between files paths

I have a list of folders and inside every folder I have the file " file.txt" which has the same name in all the folders. I wanted to collect the path for this file from all the folders and save it in ...
3
votes
2answers
108 views

Add a line below each line matching a pattern only if not already present

Can sed add a new line below a specific content, if the input content exist then leave it ? Current content of the file ssss Hostname example.com Os version rhel5.6 apache 4.2 Hostname example2.com ...
7
votes
5answers
604 views

How to find lines that begin with **

I need to find if any lines in a file begin with ** . I cannot figure out how to do it because * is interpreted as a wildcard by the shell. grep -i "^2" test.out works if the line begins with a 2 ...
1
vote
2answers
1k views

Keep newlines in output of cut

Let's imagine we have a file: foo bar foo1 bar1 I want to cut every second word in every line, so I want file to look like this: foo foo1 I am trying to use cut -d ' ' -f -1 but what I get is: ...
1
vote
2answers
132 views

Remove leading whitespace before possible shebang

I have a large collection of non-binary files in one place. Some of them have shebangs and of those some have (for some inexplicably reasons) whitespaces in front of the shebangs. This includes empty ...
1
vote
1answer
51 views

insert the content between the matching pattern in shell script

I want to insert the content between the matching pattern in shell For example : file called input.txt : var a = [ ] file called output.txt : 1152 1185 1185 I want to insert the values ...
1
vote
2answers
8k views

How to remove a column or multiple columns from file using shell command?

My file, ARCHIVE B1_NAME B2_NAME B3_NAME ELEMENT INFO_NAM WERT PROCID -------- -------- -------- -------- -------- -------- ---- ------ ...
0
votes
2answers
30 views

BASH get value from string

I have this string stored in a variable <li class="rainbow-list-item southern disrupted " data-line-id="lul-southern" data-severity-codes="4,6,9" data-mode="national-rail"> and I would like ...
1
vote
2answers
67 views

Retrieving five random items from a list using sed

How can I retrieve randomly selected five different items from a list using sed? My list is something like below. Each item begins with an asterisk at the beginning of a line. * asterisk* star ...
1
vote
1answer
36 views

Compare dates in a list

So I have a list of dates and I need to develop a script that keeps a rolling count of how many dates are older than 14 days (date --date="14 days ago" +%Y%m%d). Not sure how I can have the date check ...
1
vote
2answers
68 views

how to use \n( and )\n as delimiter in awk

I have a file which contains below data 7[label = "ScanStep: T_b0\n(T.a = 1)\na\nb\nc\nd\ne\ndob\ntimestamp1\nUnc: Integer(8)\nUnc: Integer(8)\nUnc: Varchar(80)\nUnc: Numeric(10,2)\nUnc: Varbinary(80)...
15
votes
3answers
11k views

How to sort the string which combined with string + numeric using bash script?

This is the data what I want to sort. But sort treats the numeric to string, the data it no sorted as I expected. /home/files/profile1 /home/files/profile10 /home/files/profile11 /home/files/...
1
vote
1answer
61 views

Need to strip off the comments in double quotes

I have test case which contains string message in double quotes and I want to strip off data in double quotes. I used awk command to strip off comment section data but it doesn't work awk '/^"/ { ...
2
votes
2answers
25 views

less combined with sed color sequences prevents page breaks

If I use the command below which colors the lines output in yellow, it essentially turns less into cat, printing out the entire file and disabling all of the features I need with less, such as ...
2
votes
1answer
99 views

How to sort columns independently? [closed]

$ sort -t $'\t' -k 1rn,1 -k 2,2rn -k 3f,4 listaprezzi 2050 900 bananas 5 1905 700 grapes 17 250 4000 oranges 10 230 9200 ...
0
votes
1answer
52 views

Using multiple sed commands for text manipulation

I have a bash file, in which I would like to make several changes. sed -i 's/ / /g' testfile sed -i -e 's/#[a-z]$//' -e '/^$/d' testfile sed -i 's/ *$//' testfile sed '/##=/ r header' ...
6
votes
3answers
3k views

How to interleave the lines of two or more files?

I have tried to get the 2 files output in a single file. I have tried below command: cat file1 file2 but here file2 data is appending to file1. What I need is file1 1st line followed by file2 ...
0
votes
1answer
37 views

Proper way to convert PDF to word from bash command-line

I need to convert 1K pdf files to doc on a debian server. I can convert a PDF to word using libreoffice commandline: libreoffice --headless --invisible --convert-to doc Sample-doc-file-100kb.pdf Or ...
3
votes
3answers
39 views

awk to cut portion of a field and still print entire line

I have this line: 08:30:02.480507 IP 192.168.100.150.65119 > 192.168.100.151:53 59865 [1au] A? click.em.redbox.com. (48) I need to cut out the ".480507" in the timestamp so the line looks like ...
1
vote
3answers
81 views

Find and Replace with command line

my log.txt file includes ... mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 ... how can I replace mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 with mynetworks = 127.0....
2
votes
1answer
29 views

Merging specific columns of 2 files based on field match

I know I'm not the first one asking this but my code still does not work: File 1: gi|1283| tRNAscan exon 87020 88058 . - . transcript_id "Parent=tRNA-Tyr5.r01"; gi|3283| tRNAscan exon 97020 97058 . +...
2
votes
2answers
104 views

Extracting positive/negative floating-point numbers from a string

I am trying to extract numbers out of some text. Currently I am using the following: echo "2.5 test. test -50.8" | tr '\n' ' ' | sed -e 's/[^0-9.]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' This ...
1
vote
2answers
49 views

Make the 1st column as header and list its corresponding values using shell script

I have a large file contents are as shown below :- Quantity 20589 Quantity 12297 Quantity 100346 Quantity 0 Quantity 141999 Quantity 23662 Quantity 551071 Quantity 72917 ...
0
votes
0answers
30 views

shell scripting using sed

I want to compare specific string surrounded by alphanumeric and some special chars in file. For example: 5efa4083-7157-437a-ab9a-652ced2fc2ea;: AAA :;5efa4083-7157-437a-ab9a-652ced2fc2ea;BBB I ...
2
votes
1answer
122 views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
0
votes
2answers
2k views

Sum two columns from different files

I have two files like this: File1: -54.005 -67.405 0.1 -54.05 -68.7833 0.2 -54.05 -68.7333 0.3 File2: -54.005 -67.4050 70 12.7 -54.05 -68.7833 167 12.5 -54.05 -68.7333 205 12.6 ...
0
votes
1answer
44 views

Why Blank output of this `sed … <<END_SED | cut …`?

The following sed returns (...| od -c) without ...|cut -d "\n" -f 0000000 1 9 2 \n 2 5 0 \n 0000010 Pseudocode # http://unix.stackexchange.com/a/290407/16920 sed -n -f - /usr/share/...
15
votes
4answers
29k views

How to insert text before the first line of a file?

I've been looking around sed command to add text into a file in a specific line. This works adding text after line 1: sed '1 a\ But I want to add it before line 1. It would be: sed '0 a\ but I ...
3
votes
2answers
348 views

grep: How to find Closing Bracket?

One part of /usr/share/X11/xkb/symbols/us starts with xkb_symbols "dvorak" { and ends with the closing curly bracket }; which line-number I want to find. partial alphanumeric_keys xkb_symbols "...
-3
votes
2answers
38 views

Convert text file to matrix format [closed]

I have a input files with 3 columns each- File1 - SNP Sample ID Genotype RS1 Sample1 AG RS1 Sample2 GT RS1 Sample3 AG RS2 Sample1 AG RS2 Sample2 TT RS2 Sample3 GG RS3 Sample1 GG RS3 Sample2 AG ...
0
votes
4answers
55 views

Delete specific line numbers (passed as variable) from a file in linux

I have two files. One having list of lines (which I don't require) say Seqlist and other text file (from which I intend to delete those corresponding lines) say ContentFile $cat Seqlist 3 4 ...
1
vote
4answers
103 views

How can I cut the character from “Thu Jun 2 08:11:53 PDT 2016” such that to display only 08 11

How can I cut the character from "Thu Jun 2 08:11:53 PDT 2016" such that to display only "08 11"
7
votes
2answers
121 views

Make GNU indent break long comments

Is there a way to convince GNU indent to break long comment and change it to multiline comment? Something like this: // Very long comment, longer than 80 characters. Just imagine that. To this: /* ...