General :: Grep Lines Containing A Certain String PLUS The Line Following That Line?

Sep 1, 2009

I have a dataset (see example below) that I would like to go through and copy all lines containing a certain string ("LGIG") plus the line immediately following that line to a new file. I have no problem grepping lines containing the string LGIG but I'm lost how to translate that to line number and shift up one line number for each instance of that string.

Example input file:

[code].....

View 5 Replies


ADVERTISEMENT

General :: Deleting First Line With Unique String Then All Subsequent Lines Thereafter?

Jan 20, 2011

I am doing molecular dynamics where I have to edit files. I have looked at tutorials for grep and sed but can't find my solution. The files produced in my simulations look something like this:

ATOM 1825 NE2 GLN 112 113.646 27.895 14.456
ATOM 1826 HE21 GLN 112 114.020 26.957 14.490
ATOM 1827 HE22 GLN 112 112.649 28.039 14.388

[code]...

View 5 Replies View Related

General :: Getting The Line Of String From Previous Pipe Output By Line Number?

Feb 8, 2010

After running the following command, I get:

[root@yukiko /]# find / -iname .bashrc
/home/clamav/.bashrc
/home/vpopmail/.bashrc
/etc/skel/.bashrc
/root/.bashrc

But I would like to have a command that prints a specific line by supplying the command with the line number, for example:

[root@yukiko /]# find / -iname .bashrc | getline(2)
/home/vpopmail/.bashrc

Is there such a command on CentOS?

View 3 Replies View Related

General :: Sed To Display The Pattern String - The Line Above It And The First Line Of That Para

Mar 30, 2011

I need to grep for a particular string and if found need to display the line containing that string, the line above that and also the first line of that paragraph.

Can this be done via sed.

Eg, My Paragraphs

OA connectA

Enclosure:

Interconnect Module #6 Status:

Here, if I grep for Critical, it should display the following

Similarly if I grep for Degraded, it should display

View 3 Replies View Related

Server :: Find A String In A File And Delete That Line As Well As X Lines After?

Jun 24, 2010

I need to find a string in a file ... then delete the line it is on, as well as the next 6 lines. Or, delete the line the string is on and all subsequent lines until the search finds the character "["

example:

filename = test.txt

contents:
[foo]
test>test
test>test
test>test

[Code]....

so, in this example. I'd like to search the file for string 'foo' and delete all lines from that line until [bar] (not deleting the line with [bar])

View 3 Replies View Related

Software :: Grep Query To List 1 Line (which Is Fixed) And The Next Line After It (variable Text)

Jan 20, 2011

How can I list the following with grep. I want to extract 2 lines fron a text file The fixed known part if it exists will static text and the text line after it will change.

A sample file
.
.
textline1

[code]....

If the fixed part does Not exist how can I return error code 1

View 3 Replies View Related

General :: Get A Word From A Line Using Sed Or Grep

Mar 30, 2010

I am trying to get a word from a line using sed. Following is the line which I want to use.

inet addr:10.245.86.15 Bcast:10.245.87.255 Mask:255.255.254.0 inet6 addr: fe80::1031:3dff:fe01:55e1/64 Scope:Link

From the above line, I need the ip address like 10.245.86.15 only.

View 4 Replies View Related

General :: Command To Grep Complete Line

May 11, 2011

cat filename| awk '{print $3}' | cut -c -3 | cut -c 2- | grep 66

this returns the lines containing "66" at 2nd 2 characters of 3rd column of a line, now i need complete lines for this, how can i do it?

View 6 Replies View Related

Programming :: Replace An "entire" Line Containing A Particular String With A New Line?

Mar 12, 2010

I think this can be done using sed. Let's say I have file called, "orig.txt" with following contents:

Code:
[User Prefs]
Ignore Unrequested Popups=1
DevTools Splitter Position=500
History View Style=0

[Code]....

So basically if a line contains the word "Home URL" then go ahead and replace that *entire* line with the supplied *new* line.

View 4 Replies View Related

General :: Add A Line In A File Before The Last Two Lines?

Aug 2, 2010

I need to add a line in a file before the last two lines using a script using standard linux editors like sed but i can't figure it out.

View 2 Replies View Related

Programming :: Pthread - Take String From The Command Line And Creates A Thread To Print The String

May 3, 2011

I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.

[Code]....

One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?

Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.

View 6 Replies View Related

General :: Catch Up A String In A Line?

Jun 17, 2010

I would like to make a shell script that will do the following :- have a web-page using curl- download a picture from the web-page- have a line in the source code of the web page
- catch a string (a link patch) from the line- go to another page of the website from the result of the previous step- repeat all this until there is no match for step 3I know how to :- have the web-page source code using curl (simple, we just have to make "curl- download the picture (as simple as the first step)- have a line in the source code (grep is made for that, isn't it ?)- go to another website from the result of the previous step (it's the same as the first step)But I really don't know how I can do the fourth step of my script.

In facts, I don't know regular expressions and even the shell command that can help me to do this.To be more clear, I would like to store in a variable the string represented by the star (*) in this : <a href="*">Next ></a>

View 12 Replies View Related

General :: Grep Command - Show The Files But Not The Line Count

Oct 31, 2010

This has to also show the line count. I can get it to show the files but not the line count. What is the single command used to identify only the matching count of all lines within files under the /etc directory that contain the word „HOST? List only the files with matches and suppress any error messages.

View 4 Replies View Related

General :: Using Grep To Remove Line And Write Back To Same File?

Feb 10, 2010

remove a line starting with specific word with grep. Here is what I found

grep -v '^cc$' data.txt

Here I remove all lines with on 'cc' in that line. But I want the result write back to data.txt

I try several ways

grep -v '^cc$' data.txt > output.txt # works but to another file
echo `grep -v '^cc$' data.txt` > data.txt # didn't work, all carets gone, become one line
grep -v '^cc$' data.txt > data.txt # data.txt is empty after running this

How can I save the result of grep to the input file?

View 4 Replies View Related

General :: Multiple Lines At The Command Line?

Feb 22, 2011

I've seen a few tutorials that have commands and parameters on multiple line, like the one below:

Code:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

I can copy and paste this in Putty, but what if I want to manually type it? If I press return, the first line gets processed, so how do I insert a new line?

View 4 Replies View Related

General :: Grab Line Based On String?

Aug 9, 2011

i have a file with a lot of lines in it, and iould like to grab just the line that contains a string i've specified in a variable... Let me know if you want a sample of the file.

View 3 Replies View Related

Programming :: Using Sed Replace Line Containing Particular String By A Single String?

Oct 16, 2010

I have a set of lines as ahown below:

Leon went to school
Leon came back from school..
Leon had dinner...

I have to replace the line containing "dinner" by a single string LUNCH...

View 2 Replies View Related

General :: Remove Line Breaks From Lines Ending With A Comma?

Nov 10, 2010

I have a CSV file that's created in an application that can't output lines longer than 250 characters. the data fields, all together, are longer than this. how would I remove the line break from every line that ends with a comma? For example:

A,B,C
D,E,
F
G,H,I

becomes:

A,B,C
D,E,F
G,H,I

View 1 Replies View Related

General :: Delete Duplicate Lines Without Removing First Instance Of That Line?

Feb 7, 2011

I have a file "test.txt" with following data

#1
aaa
#2
bbb
#3
aaa
#4
ddd

I wanted it to be displayed as

#1
aaa
#2
bbb
#4
ddd

I used awk "'!x[$0]++' test.txt > file.new"
,but it deleted #1 also.I tried using uniq command but i didn't work.
Can anyone Please let me know is there any way to do this using shell script.

View 2 Replies View Related

General :: Replace Nth Occurence Of String In Each Line Of A Text File?

May 20, 2010

I have large text files with space delimited strings (2-5). The strings can contain "'" or "-". I'd like to replace say the second space with a pipe. What's the best way to go?
Using sed I was thinking of this:

sed -r 's/(^[a-z'-]+ [a-z'-]+) /1|/' filename.txt

View 2 Replies View Related

General :: Perl Command To Replace String By Line Numbe?

Jul 10, 2010

I want to know the Perl command to replace a string by pointing the line number. I know how to replace a string without pointing a line number but I am in need to replace only the two matching string in a file

View 6 Replies View Related

Programming :: Copy And Replacing Specific Line From File1 To File2 Line By Line

Mar 22, 2011

I have two files, file1.traj and file2.traj. Both these files contain identical data and the data are arranged in same format in them. The first line of both files is a comment.

At line 7843 of both files there is a cartesian coordinate X, Y and Z ( three digits ). And at line 15685 there is another three digits. The number of lines in between two cartesian coordinates are 7841. And there are few hundreds of thousands of lines in a file.

What I need to do is copy the X Y Z coordinate (three digits) from file1.traj at line 7843 and paste into file2.traj at the same line number as in file1.traj. The next line will be 15685 from file1.traj and replace at line 15685 at file2.traj. And I dont want other lines (data) in file2.traj get altered. This sequence shall be going on until the end of the file. Means copy and substitude the selected lines from file1.traj into file2.traj.

I tried to use paste command but I cant do for specified line alone.

Here i showed the data format in the file. I used the line number for clarity purpose.

Code:

View 10 Replies View Related

General :: Create A Single Line Of Output From Multiple Variable Lines Of Input

Feb 3, 2010

I need to create a single line of output from multiple and variable lines of input in a Linux bash shell script.

My input file looks like this:

Where there may be any number of umsecondaryphonenumber lines; if there is not a umsecondaryphonenumber line for a telephonenumber, I don't want to write any output.

So, the output file should look like:

The script I have so far is:

My question is - how do print each of the elements of an array in one record - i.e. what do I put in place of howdoiprintarray?

View 2 Replies View Related

Programming :: Access A File Line By Line, And Check The Length Of Each Line.

Feb 13, 2011

I want to access a file, and check the length of every line.After, i want to check and replace all lines with length over 10 characters, with a message.Does anyone have a clue on that?

View 1 Replies View Related

Red Hat :: Grep Array Add To End Of Line If True?

Jan 27, 2011

I want to add to the end of a line for a file that has the /usr/X11R6/bin/X in it. The /usr/X11R6/bin/X is not at the end of each line. I need to add "-nolisten tcp" to the end of each line containing the the /usr/X11R6/bin/X string.how can this be done in a script?

View 5 Replies View Related

CentOS 5 :: Grep The Line And Pipe That Into The Sed?

Sep 22, 2010

I need to simply replace a 2 lines, or one and I'll run each command separately, in a eps file. I know I can grep the line and pipe that into the sed but I would like to keep this in a sed command. I can use sed /s and get it if I copy the section out of the file and paste it. Really just trying to rewrite the boundingbox coord's in eps files.

sed -i 's/%%BoundingBox: 00 00 88 487/%%BoundingBox: 24 315 288 487/g;s/%%HiResBoundingBox: 00 00 88 487/%%HiResBoundingBox: 26 315 288 487/g' someeps.eps

View 2 Replies View Related

Programming :: Compare Two Files Line By Line And Print The Line Which Is Same?

May 30, 2011

I am trying to write a program in C which compares two files and prints the line that is equal.

Here file1.txt has

and file2.txt has

Note: file2.txt consist of only a single string where as file2.txt has multiple lines. Actually im comparing two files with md5sum values.

Here is the code but it compares only first line of files..but it should compare the whole file1..and sorry iam a beginner in C can any1 sujest some modification to this code so that..it can compare file2 with entire file1

Quote:

View 9 Replies View Related

Programming :: Insert Line Using Sed Or Awk At Line Using Line Number As Variable

Jul 25, 2011

I want to insert a line at a particular line number using sed or awk. where line number is not fixed and is in form of variable.

I want to use variable in sed or awk command.I tried something like below, but no luck.

View 7 Replies View Related

Ubuntu :: Wildcard In Sed&grep That Includes Line Endings?

Dec 21, 2010

Here's my current regular expression(used in sed):sed 's///!Start.*//!End//g' in > outThe only problem being that the wildcard . does not work across multiple lines,

View 1 Replies View Related

General :: Create Cron Tab When DSL Line Down Set Automatically Restart The Network Service While DSL Line Up?

Oct 7, 2010

How to create cron tab when DSL line down set automatically restart the network service while DSL line up?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved