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.
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.
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.
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>
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.
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?
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:
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:
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
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.
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?
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.
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