find a string and copy the string after that


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find a string and copy the string after that
# 1  
Old 06-18-2009
Bug find a string and copy the string after that

Hi! just want to seek help on this:

i have a file wherein i want to find a string and copy the string after that and paste that other string to a new file.
ex:
TOTAL 123456
find "TOTAL" and copy "123456"
and paste "123456" to a new file

NOTE: there are many "TOTAL" strings on that file.

anyone pls help me! thanks!

Last edited by kingpeejay; 06-18-2009 at 09:11 PM.. Reason: more clarifications
# 2  
Old 06-19-2009
provide some more sample input., you say there will be more than one TOTAL, so on what basis, you want to find?

Have you tried anything?
# 3  
Old 06-19-2009
For example:
2345
4567
8910
TOTAL 1234
......
3456
7890
1234
TOTAL 5678
.....

In a file, there are many lines with "TOTAL" on it. I want to find "TOTAL" on that file and copy the next string after that on that certain line. Afterwards, paste that other string a new file.
Actualy, i haven't tried anythng yet. I don't know where to start. Tnx!

---------- Post updated at 01:14 PM ---------- Previous update was at 01:12 PM ----------

And there is no fixed interval on the occurence of the "TOTAL"s lines. Thanks!
# 4  
Old 06-19-2009
You mean to say TOTAL 1234 should go in new file
and likewise TOTAL 5678 also should go in the same new file.

or only 1234 and 5678....in any case first read
man grep, and man cut
# 5  
Old 06-19-2009
Only 1234 and 5678, in a new file with this format:
1234
5678
...

Can i have a sample command for this? Thank u very much!
# 6  
Old 06-19-2009
Try it for 5 mins...with grep and cut
look for grep -w option
and cut -f and -d options.
# 7  
Old 06-19-2009
I know grep can find "TOTAL" but i don't know how to copy the next string.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find previous string based on an input string?

Hi, I did some research but cannot find the right solution so hopefully someone can help me here. I have a long string format like: VAR=111:aaaa,222:bbb,333:ccc it could be VAR=111:aaa,222:bbb,333:ccc,444:ddd, etc what I looking for is eg. if I give ccc, it will return me 333... (2 Replies)
Discussion started by: netbanker
2 Replies

2. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

3. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

4. Shell Programming and Scripting

Find string in XML file, copy contents of section

I am new, really new to bash scripts. I want to search an XML file for a certain string, say "1234567890" Once found, I want to copy the entire contents from the previous instance of the string "Entity" to the next instance of "/Entity" to a txt file. And then continue searching for the... (4 Replies)
Discussion started by: jrfiol
4 Replies

5. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

6. Shell Programming and Scripting

input a string and copy lines from a file with that string on it

i have a file1 with many lines. i have a script that will let me input a string. for example, APPLE. what i need to do is to copy all lines from file1 where i can find APPLE or any string that i specify and paste in on file 2 thanks in advance! (4 Replies)
Discussion started by: engr.jay
4 Replies

7. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

8. Shell Programming and Scripting

Find a string in textfile, erase $num lines after that string

I have a textfile containing text similar to the following pattern: STRING1 UNIQUE_STRING1 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING2 STRING2 STRING3 STRING4 STRING5 STRING1 UNIQUE_STRING3 STRING2 STRING3 (6 Replies)
Discussion started by: ilcsfe
6 Replies

9. UNIX for Dummies Questions & Answers

Read a string with leading spaces and find the length of the string

HI In my script, i am reading the input from the user and want to find the length of the string. The input may contain leading spaces. Right now, when leading spaces are there, they are not counted. Kindly help me My script is like below. I am using the ksh. #!/usr/bin/ksh echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies

10. UNIX for Advanced & Expert Users

find and copy string in a file

Hello there I need to find a string in an file, and then copy to a new file from the previous 6 lines to 41 lines after the string. So, what i need to do , and just don't know how, is to find the string and copy 48 lines where the string would be in the 7th line. I don't know if i can do it with... (10 Replies)
Discussion started by: vascobrito
10 Replies
Login or Register to Ask a Question