Manipulation of text by programs, scripts, etc.

learn more… | top users | synonyms

2
votes
2answers
51 views

Need to obtain Awk output in specific sequence

Data in file: 1234567-5678907 3456789-1234563 3456789-1234567 . . . . n Now I want the output in the below format: 1234567-5678907,3456789-1234563,3456789-1234563....n I have used below command ...
2
votes
1answer
30 views

ksh/bash Formatting Files through sed by cat file|sed command

I am new to unix platform, (Alternate Approaches can be discussed) I am trying to change the colors of content of a file conditionally. My file is: A B C D Value Value Value Value Value ...
1
vote
2answers
27 views

How to merge the lines in Unix (Sun Solaris) in a specific pattern

I have below n number of lines in a flat file: uk,1234560000 uk,6789067000 uk,4567890000 . . . n lines Now I have to make it in below format: ...
1
vote
1answer
35 views

If statement in shell-script only half-working

I've been trying to write a script to rotate my monitor, I'll then assign it to a keyboard key. I've been fairly successful in making it rotate once, however when I run the script again, it doesn't ...
1
vote
1answer
34 views

Cut some fields from a text file to another

I have the following command: grep -owf champs.txt t.txt and I want to cut the result of this command from the file t.txt to another file. I know that it can be achieved by a nested command but I ...
3
votes
2answers
95 views

sed: inserting text before end of <HEAD> section

I need to insert some text into an HTML file before the end of the HEAD section. I'm trying: sed -i "s#</head>#<style> @page { prince-shrink-to-fit: auto } ...
2
votes
3answers
192 views

How to find a specific 'string' and print out the whole line?

I have a file named myfile.csv containing the following: abc:123:myname:1231 def:423324:arbitrary:value:string StackExchange:Unix:Linux From the terminal I run ./myscript.sh def The contents of ...
1
vote
4answers
102 views

matching and merging lines with awk & printing with Solaris

I want to merge the matching pattern with awk on a Solaris system. $ luxadm probe No Network Array enclosures found in /dev/es Found Fibre Channel device(s): Node WWN:2000000c50f1c8da Device ...
-3
votes
2answers
53 views

match two files and filter out [duplicate]

I have two files file A >TCONS_00000075 gene=XLOC_000030 CCGCCGGCTGCTGCGCGCACCGACTTGTCACCACCCCAGCACGTCCTCCACGTATACAAGCGCTACGGTC ...
14
votes
9answers
461 views

Filter or pipe certain sections of a file

I have an input file with some sections the are demarcated with start and end tags, for example: line A line B @@inline-code-start line X line Y line Z @@inline-code-end line C line D I want to ...
0
votes
5answers
113 views

Read File word by word

My problem is to read a text file word by word and recovers every word in a variable. I tried to do: while read ligne; do { for ( i=1; i<= length ($ligne); i++); do { var=$(awk '{print $i}' ...
0
votes
5answers
172 views

grep to fetch whole line

I have a file like: Chr1 Cufflinks exon 7136 7944 . + . gene_id "XLOC_000001"; transcript_id "TCONS_00000003"; exon_number "5"; gene_name "LOC_Os01g01010"; oId ...
0
votes
0answers
25 views

seeking hints for correct escaping of sed commands WITHIN yaml

I am having a hard time finding the issue why following lines of "code" break my cloud-init config. Basically I am calling a son object as part of the DigitalOcean API which has a yam format - I got ...
1
vote
2answers
50 views

How to obtain a plain (raw) binary dump of any file in Unix/Linux?

I have read many similar question on the Stack Exchange community but none of them address a 'clean' binary dump. I have used: xxd and sed combinations to try to obtain a clean binary dump from any ...
2
votes
0answers
58 views

Bash regular expression comparison fail for hex byte \x01

Bash regular expression fails to compare correctly for $'\x01' when End-Of-String char $ is used. All other byte values (seem to) compare correctly. Using GNU bash 4.1.5(1). Is this a bug, or is ...
0
votes
3answers
75 views

Remove special characters in a text file

I have a text file which contains in each line a sql query. For each line, I need to remove some special characters. Expl: if I have: select * from Users; insert into Users values ...
2
votes
4answers
75 views

Why isn't this awk command doing a full outer join?

Objective: Merge the contents of two files using common key present in the files file1.txt ========= key1 11 key2 12 key3 13 file2.txt ========= key2 22 key3 23 key4 24 key5 ...
2
votes
4answers
195 views

How to 'drop' characters from in front of a string?

I have a string that I would like to manipulate. The string is H08W2345678 how would I be able to manipulate it so the output is just W2345678? Similarly if the I wanted to drop the last 4 ...
0
votes
2answers
30 views

How to scrape multiple IP's and add in a script as a variable?

I am trying to add in my script an awk statement or a: if; else; then if eth0:4 is a match then put in eth0:4 IP How would you get the IP in your script as a variable if you have multiple IP's ...
-3
votes
0answers
38 views

Regex: match word in line 1-3 times

My question is about regular expressions and searching for text. I need to search for all lines in text that contain one ceratin word, let's say "cat", one, two or three times.
0
votes
1answer
33 views

Vim: Count all occurrences (including multiple on the same line) of char or word

I try to count all occurrences of a char or word in a file with Vim. This means multiple occurrences of the same word in the same line should be taken into account as well. This has been discussed in ...
0
votes
2answers
72 views

How can I filter ping results by time?

How do I filter out any pings that are under a certain ms, ie, only echo ping responses above 500ms to the text file? IP=$1 SECONDS_Between_Pings=$2 ping -i $2 $1 | while read pong; do echo $(date) ...
0
votes
1answer
22 views

text processing

I have two files. file A : Chr1 Cufflinks exon 2903 3268 . + . gene_id "XLOC_000001"; transcript_id "TCONS_00000002"; exon_number "1"; oId "CUFF.1.2"; tss_id "TSS1"; ...
4
votes
3answers
118 views

Remove duplicate lines while keeping the order of the lines

[root@server]# awk '!seen[$0]++' out.txt > cleaned awk: (FILENAME=out.txt FNR=8547098) fatal error: internal error Aborted [root@server]# The ""server"" has: 8 GByte RAM + 16 GByte SWAP, x>300 ...
3
votes
4answers
234 views

Using sed for brackets

I would like to find out, if, in my file, there is a right number of brackets. I can make my file look like (((()))()(())) ((()))() How can I use sed to compute those brackets and print yes or no ...
2
votes
4answers
126 views

How do I extract the first integer from text string in a column of a tab-delimited file?

I work in Medical Genetics and often have delimited text files where in one column (ex. column 5) there is a text string with a "mutation" in our jargon: c.2458C>T or c.45_46delAA or ...
0
votes
1answer
21 views

How to find & replace pattern WITHIN specific pattern using sed

IT seems that 'sed' and I will never be friends... How can I find and replace a pattern within a range (within another pattern)? In words: Find: AllowOverride None within the following range and ...
0
votes
2answers
32 views

Vim: Substitute based on another match in the line

I have rather large files in which I need to substitute NX for N1 but only if the line already contains NX as a pattern. So far I do it manually by first searching for occurrences of NX with: /NX ...
2
votes
1answer
52 views

Using find and sed to copy 20th line of many files into one file

I have a folder called "PKA1" Within this folder I have several folders that look as: 1eV, 2eV .... 30eV Within each of these I have subfolders I have a file called PKA.dump I want to copy the ...
4
votes
2answers
139 views

Increment a variable using a Bash script

I have a file that contains the following text. // // test_file.h // test project // // Created by Test User // #ifndef test_file_constants_h #define test_file_constants_h // Generic includes ...
5
votes
5answers
356 views

How to replace a word with new line

I have a text file with following data and each row ends with |END|. T|somthing|something|END|T|something2|something2|END| I am tryig to replace |END| with \n new line with sed. sed ...
0
votes
1answer
43 views

Error while passing variables for keyword match using sed

I am a beginner in scripting. I am writing a bash script for text processing where this command is giving me error: sed -e "/\<$7\>/ /\<$5\>/$6/" < "$2/$1" > "file.tmp" This is ...
5
votes
7answers
418 views

Turn list into single line with delimiter

I have to take a list (loads) of IP addresses in this format: 134.27.128.0 111.245.48.0 109.21.244.0 and turn them into this format with a pipe in-between (IPs made up) 134.27.128.0 | ...
2
votes
6answers
137 views

Join lines of text with repeated beginning

I have a long text file (a tab-file for stardict-editor) which consists of lines in the following format: word1 some text word1 some other text word2 more text word3 even more and would like to ...
3
votes
1answer
37 views

Extract first word after pattern that includes `[…]`

I have an issue when I try to extract the first word after grep matches my pattern . Let me show you an example : cat test.txt [profile dev] xxx xxx [profile prod] xxx xxx now I want to extract ...
0
votes
3answers
40 views

How to find the word after a given pattern using cut?

I have a file that looks like this: -config1 -config2 param2 -config3 param3a param3b -config4 param4 and I can use the following to extract param2: echo $(<file) | cut -d' ' -f3 However I ...
1
vote
1answer
36 views

Trouble with Sed Syntax

I'm modifying raw PCL/PS files (mixed) and for some reason I can't get my Sed syntax right for the true beginning that I want it to grab. Here's a sample output from the strings command: *c50B *c0P ...
1
vote
2answers
39 views

SED replace after ignoring

There are many lines in a text file and I would like to change the value true to false using a one line script. bash-3.2$ grep online test.txt # online = false --> ONE SHOT import (delete all ...
0
votes
2answers
32 views

Select lines and format

Is there a way to format the following output so that only lines 1 and the respective lines that state the "rule" name print out? Depending on the configuation, the "rule" line could vary. It could be ...
0
votes
1answer
44 views

Modify part of line if keyword is found using sed? [duplicate]

I want to modify a line if a specific keyword is found in a line. CS_CODE, SM_NUM, PORT_NUM, DEV_PORT_NUM, DIRNUM, MAIN_DIRNUM, BILL_NO, ADR_NAME In above line, if 'PORT_NUM' is present then ...
2
votes
1answer
51 views

How to select lines and reformat command output?

Is there a way to format the following output so that only lines 1 and 4 print out? It would be best if the first line and fourth line could come out on the same line like this: sw pool test(no ...
1
vote
5answers
57 views

keep out line break

I have some files with this structure: 2015-03-25 17:08:17 sysUpTimeInstance 93474;^M 1.ValueforState=2500 I want to replace the line break, and leave the third line with the second line, I mean, ...
-2
votes
1answer
41 views

how to print new word after two lines using awk

I need to insert a blank line after two lines in a file that i did with cat rat hat pot NOT lot big big big sit sit sit awk '{print};(NR%2==0){print ""}' cat rat hat pot NOT ...
1
vote
1answer
36 views

How to match parameter and replace the value after “=” separator

the perl one liner command to replace Value in file is simple: perl -i 's/oldval/newval/g' file.txt but what should be the perl one liner syntax in case we want to replace the value on specific ...
1
vote
2answers
58 views

sort only the first column and uniq

I have a list as such below: 1,cat 1,dog 2,apple 3,human I'd like an output like this: 1,cat,dog 2,apple 3,human So value 1 from column 1 contains the value of cat and dog from ...
2
votes
3answers
109 views

Sorting numbers and respective units in columns

I have a list like this: 1,kg,cat 1000,g,dog 20,g,apple And I want to sort it by weight. 1 kg and 1000 g would be the same, so I'd like to have my rows sorted by weight. My data set is ...
2
votes
3answers
116 views

How can I extract the text between two strings in a log file?

I think I have a very similar question to this one but I see it was closed due to being unclear so I'll create a new question. I've got a log file that contains one-line entries with multiple ...
1
vote
2answers
51 views

Remove paragraph from file

I have a file (file.php) like this: ... Match user foo ChrootDirectory /NAS/foo.info/ ForceCommand internal-sftp AllowTcpForwarding no GatewayPorts no ...
1
vote
1answer
39 views

How to truncate text lines to N characters maximum? [duplicate]

Given a text file, or the output of a command, how can I truncate it so that every line longer than N characters (usually N=80 in a terminal) gets shorten to N characters maximum?
0
votes
1answer
45 views

Search a file for a string in multiple directories

Can someone please help me with a command to search a file for a string in multiple directories? I am searching for the VIP in httpd.conf in multiple httpd instances. I am using: find ./ -name ...