Tagged Questions
1
vote
2answers
60 views
Split using sed
I have to split
[X] ||| you owns the [X,1] ||| you own the [X,1] ||| 1 0.02020 0.07847 0.36788 3 -0.00000 -0.00000
at the pipes and output those line whose 2nd and 3rd argument are different.
1
vote
2answers
119 views
Unix command for pattern matching
I want to count the number of words and print the matched pattern lines which matches exactly with following pattern:
abc-ERROR:
The input File contains:
# abc-ERROR: xyxxkkfgfr
# def-Error: ...
-8
votes
1answer
61 views
can anyone help me with this sed and grep? [closed]
(a) SED
Given a file, replace all the sequences of 4 or more digits with the
word "cat".
(b) GREP
Given a file, display all the lines starting with the word "cat" and
ending with the ...
2
votes
2answers
82 views
add “#” in begining to selected lines in File
Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B
File A
abcd
abdc
sdfg
asdfa
jon
ram
File B
jon
abcd
grep file B from file A and add "#" ...
0
votes
3answers
49 views
Grep end regex matching
On OS X, system_profiler SPHardwareDataType outputs:
Hardware Overview:
Model Name: MacBook Pro
Total Number of Cores: 4
L2 Cache (per Core): 256 KB
L3 Cache: 8 MB
Memory: 8 GB
I want to ...
1
vote
3answers
168 views
awk, sed, grep, perl… which to print out in this case?
I have this syntax in a file (http response times from analog):
<thead><tr><th class="x">seconds</th><th class="R">reqs</th><th ...
1
vote
3answers
208 views
Newbie struggles with grep, sed, awk to filter html
I am a beginner linux user, trying to teach myself how to use linux tools on a cygwin install. I decided to make up a project to try to teach myself the basics of shell scripting and simultaneously ...
0
votes
1answer
70 views
Search low values in linux files
I am working with mainframe files and it seems that the low values (x'00') exists in the records in the file which throughs off my import for fixed block
Does anyone know how to eliminate this ...
0
votes
3answers
89 views
For all files that does not contain a string, prepend a string to the file
I am trying to iterate through a list of html files, check to see if {% load static from staticfiles %} exists in the file and if it does not exists, prepend {% load static from staticfiles %} to it.
...
2
votes
2answers
59 views
sort a file based on length of the column/row
I need to sort a file based on the number of chars in the first column.
I have no idea on how to go about this. (On Linux, so sed/awk/sort is available).
An example:
.abs is bla bla 12
.abc is bla ...
3
votes
5answers
159 views
Print non-existent files from a pipe input
I have a directory of lots of .PDF and .JPG files.
There should be a .JPG file for each .PDF with the same name.
I'm trying to use a command to find .PDF files that doesn't have a .JPG file.
My ...
2
votes
2answers
261 views
extract last match from logfile till end
Using sed, grep, awk, or ruby, what's a simple way to find the last match of a string in a larger log file, and send every line following it (inclusive) to another file?
Example:
grep -A222 ...
1
vote
1answer
84 views
Display words in color
I am looking for a tool which takes a file in input and a word to search. It should display the file with color the words if it corresponds to the search.
Like grep --colors but displays all the ...
3
votes
5answers
124 views
grep device name and look for next value :
I have this output from a find command:
abc,10.11.13.14,def,1.2.3.4,geh,6.7.54.23
where abc,def and geh are device names and could be of any length and others are IP address belong to devices. ...
1
vote
4answers
916 views
How to print all lines after a match up to the end of the file?
Input file1 is:
dog 123 4335
cat 13123 23424
deer 2131 213132
bear 2313 21313
I give the match the pattern from in other file ( like dog 123 4335 from file2).
I match the pattern of the line ...
2
votes
3answers
222 views
Regex/pattern matching problem to extract data
What is the best way to remove distances in the following lines and output cdv format. Can this be done reasonably easily on the command line? I'd like to avoid having to write a full-blow script.
...
2
votes
5answers
74 views
Generate “item tag” pairs from “item,item,…|tag” lists [closed]
The characteristics of the input data:
Each line consists of two fields, separated by a pipe '|', where
the first field is a comma-separated list of items, and
the second field is a tag.
Input
...
4
votes
3answers
248 views
Delete the matching line and several more from a file
I have a text file called file_a.txt.
My first command is
grep -A 12 ".production =" file_a.txt
The output is a few block.
Each block of string contains 13 rows
I specifically want to delete all ...
1
vote
3answers
560 views
bash merge 2 lists removing duplicated
I have an embedded linux system using Busybox (OpenWRT) - so commands are limited. I have two files that look like:
first file
aaaaaa
bbbbbb
cccccc
mmmmmm
nnnnnn
second file
mmmmmm
nnnnnn
...
2
votes
3answers
402 views
Average rows with same first column
Given a file with two columns:
Id ht
510 69
510 67
510 65
5l0 62
510 59
601 29
601 26
601 21
601 20
I need a way to coalesce all rows with the same ID into one that has an average height. In this ...
0
votes
5answers
1k views
compare two files get identical list
file1.txt (50 lines)
TERYUFV00000010753
TERYUFV00000009526
file2.txt (500 lines)
TERYUFV00000009526 refids_739_known_8/10_target
TERYUFV00000018907 refids_12023_known_21/22_target
...
3
votes
2answers
343 views
What is the best way to find a list of several strings within a large text file
The short, general question is: In Unix/Linux, what is the best way to find a list of several (about 150) strings within a large text file?
I am asking this to all Unix/Linux experts as a general ...
2
votes
3answers
81 views
Need to parse a double entry table with two pairs
I have this two-entry table resulting from a program output:
Variable1 : Value1
Variable2 : Value2
Variable3 : Value3
Variable4 : Value4
Variable5 : Value5
Variable6 : Value6
...
0
votes
1answer
159 views
wget images with certain path
im looking to only grab images from a document with a certain path for example
domain.com/uploads/287167/file_name.jpg
only grab those with the uploads/number/filename
im currently doing it this ...
2
votes
1answer
943 views
Delete last character in a word but only if the character is there - in bash
How to remove last character only if it's there?
input:
OpenOffice.org/m
openOffice.org/ozm
Pers.
Pfg.
phil.
Prof.
resp.
Roonstr./m
roonstr./ozm
desired output:
OpenOffice.org
openOffice.org
...
2
votes
1answer
153 views
Oneliner to detect camelcase variables
I would like to insert some style tests as git hooks in order to stick with precise style rules.
How can I come up with a oneliner that detects and prints arbitrary camelcase variables like the ...
4
votes
3answers
201 views
Print a line only if the next line does NOT contain a particular match
I am trying to search a log file for logged activities that did not complete. For example, I log a "Starting activity for ID 1234..." and if successful, the next line will be "Activity 1234 ...
2
votes
3answers
632 views
Grepping several lines from Nmap output
I apologize in advance as this is a simple question.
So I'm attempting to scan a Class C to identify all mail servers by IP. The vast majority of IPs aren't mail servers. I'm trying to filter out the ...
2
votes
1answer
169 views
Is it a good idea to supplement shell script with perl purely for use of regex?
I'm looking for a simple way to utilize regex in a UNIX shell script where not every system will have perl extensions built into grep. What is really helpful about perl regex here is back/forward ...
0
votes
2answers
234 views
Removing a long string from php files - using grep and sed?
I have encountered some malware on my Linux server, and am trying to remove it from many php files.
I've tried endlessly with grep | sed and grep | tr and couldn't even erase a simple text string, ...
1
vote
6answers
261 views
Print word that doesn't contain character
My file is in the following format:
this!,is!,another!,test,yes!
this!,is!,another!,column,yes!
no,not!,another!,column
My output should be:
test
column
no
It shouldn't contain the '!' ...
1
vote
2answers
830 views
Recursively replace string in files
I want to replace the backslash in the string page_path\example_filename.txt with a forward slash. I also want to be able to run this on a large file system and have it recursively search all ...
1
vote
2answers
1k views
grep piping into sed, replacing inline; but I want sed to print the filename and changed line. Is it possible?
Here's my command (break intentional):
grep FOO "/Users/gjtorikian/blah" -l | xargs sed -i '' '/FOO/{s/FOO/BAR/g; w /dev/stdout
}'
At the high-level: grep for FOO in the blah directory; pipe in ...
6
votes
1answer
224 views
How to detect and delete lines containing ˆ@
I have a simple problem:
In my file, the are lines containing the string ˆ@ˆ@ˆ@ˆ@ˆ@ˆ@. I just want to delete all lines with this string, using for example the sed or grep commands.
And I would like ...
2
votes
1answer
273 views
Getting data section with maximum element
I have some data stored in JSON-like format.
{
{
value1: 14,
value2: 12,
value3: 1
},
{
value1: 4,
value3: -1
}
}
How can I get subsection ...
1
vote
2answers
278 views
pattern search and display the last occuring pattern?
I have a log file containing startup and shutdown times for everday.
I want to see the last pattern pattern for startup and shutdown(which is located at the end of the file being updated everyday).
...
5
votes
1answer
5k views
Return only the portion of a line after a matching pattern
So pulling open a file with cat and then using grep to get matching lines only gets me so far when I am working with the particular log set that I am dealing with. It need a way to match lines to a ...
3
votes
3answers
799 views
Show lines matching a pattern and the 4 lines before each
For example, from this file:
CREATE SYNONYM I801XS07 FOR I8010.I801XT07
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
CREATE SYNONYM I801XS07 FOR ...
4
votes
3answers
2k views
How do I grep without leading whitespaces?
I'm greping through a large codebase, and leading whitespaces and tabulation seem to be quite annoying. Is there any way to get rid of it?
grep -R "something" ./
E.g, instead of:
foo/bar.cpp: ...
2
votes
4answers
2k views
Deleting Lines Containing a Specified String in Different Files
Suppose there are two files in web/ named foo.php and bar.php. The 1st line of foo.php is "sdajgeSTRINGdsad" and the 10th line of bar.php is "gdfhu98324STRING". The task is to first locate these two ...
2
votes
2answers
463 views
sed, grep, or tr command that returns only Latin characters from a UTF-8 file
I am working with the text of the 300 tang poems, which unfortunately is a single file containing both Chinese and English. Since I am interested in 'extracting' the English, I hope to use sed, ...
1
vote
3answers
312 views
Switch from grep to sed
I have a files students.txt, with lines of the form:
Surname, Forename: Day.Month.Year: Degree
For example:
Smith, John: 15.01.1986: MSc IT
Taylor, Susan: 04.05.1987: MSc IT
Thomas, Steve: ...
4
votes
5answers
9k views
Multiline pattern match using sed, awk or grep
Is it possible to do a multiline pattern match using sed, awk or grep? Take for example, I would like to get all the lines between { and }
So it should be able to match
1. {}
2. {.....}
3. ...
2
votes
3answers
470 views
Filtering paths to a specific depth
I'm using rsync and the flags -nPaAXz ~/ to check which files are going to be copied.
This is far too verbose to make any sense of.
How could I filter the output so I view the list of files/folders ...
2
votes
3answers
2k views
Extracting tokens from a line of text
Using bash scripting and grep/awk/sed, how can I split a line matching a known pattern with a single character delimiter into an array, e.g. convert token1;token2;token3;token4 into a[0] = token1 … ...
2
votes
1answer
448 views
Using grep/sed/awk to classify log file entries
I need to process a very large log file with many lines in different formats.
My goal is to extract unique line entries who have the same starting pattern, e.g. '^2011-02-21.*MyKeyword.*Error', ...
9
votes
2answers
2k views
How to remove multiple lines per occurrence in a file?
Say I have this 857835 line file, containing stuff like this:
a1
rubbish1
rubbish2
rubbish3
rubbish4
a1
rubbish5
rubbish6
rubbish7
rubbish8
And I wish to remove all occurences of a1 and the next ...
45
votes
6answers
7k views
Is there a basic tutorial for grep, awk and sed?
I've been a Linux user for a while, and I've a pretty decent understanding of most the common command line utilities. However, ones that come up and up again in relation to programming are grep, awk, ...
7
votes
4answers
4k views
grep — removing text after delimiter token
I have a file in which I need to eliminate everything after the first ; on every line.
So a file like this:
sdfsdsdf;
fsdfsddf;sdfsd;
Will result in this:
sdfsdsdf
fsdfsddf
I have looked into ...


