Copy out of File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy out of File
# 1  
Old 10-12-2012
Copy out of File

Hi there,
first post I really need advice. Before i managed my prob by reading your threads, very helpful so far!

Here is my prob:
I want to get an information out of a file with a huge amount of chars and numbers.
Itīs like:
Code:
FGH= 12345  GHJ= 23456 ZUI= 78901 THB= 12345
BHU= 23456  JKL= 56789= THB= 56789 BHU= 6789

and this a thousand times

The information of interest is the number after "THB="
So I tried with
Code:
sed -n 's/.*\THB=   \([^ ]*\) .*$/\1/p' filename1 > filename2

This is half the way I have to go. bcoz if you take a closer look at line 1 in my example, youīll recognize, that the THB is listed at the END of the line. Unfortunately my command only takes the information before the next blank... :/ so my result was
Code:
56789

How can I make my command copy the information if there either is a blank or the end of a row. No matter what is reached first? In order to get a result like:
Code:
12345
56789

Kind Regards

Last edited by Franklin52; 10-14-2012 at 07:13 AM.. Reason: Please use code tags
# 2  
Old 10-12-2012
just remove space then..

Code:
sed -n 's/.*\THB= \([^ ]*\).*$/\1/p' file

12345
56789

# 3  
Old 10-12-2012
Quote:
Originally Posted by pamu
just remove space then..

Code:
sed -n 's/.*\THB= \([^ ]*\).*$/\1/p' file

12345
56789

Thank you for your reply. I edited my post above because I described my problem a tiny bit wrong. Anyway, i donīt get where i should remove space and how it should recognize the end of a line then.
# 4  
Old 10-12-2012
Quote:
Originally Posted by Turnvater
Anyway, i donīt get where i should remove space and how it should recognize the end of a line then.
see below.. spot the difference...Smilie(see red part)
Code:
$ cat file
FGH= 12345 GHJ= 23456 ZUI= 78901 THB= 12345
BHU= 23456 JKL= 56789= THB= 56789 BHU= 6789

$ sed -n 's/.*\THB= \([^ ]*\) .*$/\1/p' file
56789

$ sed -n 's/.*\THB= \([^ ]*\).*$/\1/p' file
12345
56789

This User Gave Thanks to pamu For This Post:
# 5  
Old 10-15-2012
Simply amazing! Thank you very much!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copy the content from txt file and create a html file

I have a txt file with a list of error messages in a xml tag format, and each error message is separated with a identifier(endresult).Need to split that and copy and create a new html file.Error message has some special character. how to escape the special character and insert my data into the... (7 Replies)
Discussion started by: DevAakash
7 Replies

2. Shell Programming and Scripting

Change the file name and copy old file content to new file names.

Hi, I have a files in a directory as below :- ls -1 mqdepth-S1STC02 proc-mq-S1STC01 proc-mq-S1STC02 proc-mq-S1STC03 Whereever i have S1STC i need to copy them into new file with file name S2STC. expected output :- ls -1 mqdepth-S2STC02 proc-mq-S2STC01 proc-mq-S2STC02... (3 Replies)
Discussion started by: satishmallidi
3 Replies

3. Shell Programming and Scripting

how to copy the directory but not copy certain file

Hi experts cp bin root src /mnt but not copy bin/bigfile any help? ( I post this thread in the "redhat" forum wrongly, I don't know how to withdraw that question in that wrong forum) Thanks (6 Replies)
Discussion started by: yanglei_fage
6 Replies

4. Programming

how to copy downloaded file into my source file folder (putty/unix)

I need to "Ensure that when you download libchat.a from the VLE you have copied it to the same folder on ius as your source files. You then refer to the library (and the libraries it needs) with: gcc -o outputfile sourcefile.c -L. -lchat -lsocket -lnsl" But I have no idea what this means! (I... (2 Replies)
Discussion started by: fakuse
2 Replies

5. Red Hat

Copy certain file types recursively while maintaining file structure on destination?

Hi guys, I have just been bothered by a fairly small issue for some time now. I am trying to search (using find -name) for some .jpg files recursively. This is a Redhat environment with bash. I get this job done though I need to copy ALL of them and put them in a separate folder BUT I also... (1 Reply)
Discussion started by: rockf1bull
1 Replies

6. UNIX for Dummies Questions & Answers

Copy a windows CVS file to the unix server as a svs file

I so desperately need a script to copy a windows csv file to my unix server and i know these should be at dummies but i have no bits. it is life & no job situation help please. thanks (1 Reply)
Discussion started by: zhegal
1 Replies

7. UNIX for Dummies Questions & Answers

Copy a file from a dvd to the local AIX file system

Hi, I am a newbie to AIX, so please bear with me. I have mounted a dvd drive on AIX. I am trying to copy the file that is on the dvd drive on to the local machine. However, I get an error: cp: c1m_0001.gz: A system call received a parameter that is not valid. Can some one point me to the... (1 Reply)
Discussion started by: anurag1510
1 Replies

8. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

9. Shell Programming and Scripting

how to copy a file to a directory ,where file and dir are sent as args to a function?

Hi all, I wanted to know how i can copy a file to a directory and then verify if that file is completely copied or not? Now the issues here is that the dir and the source file are to be sent as arguments to a function( this function should actually copy the files to a dir, then check if its... (0 Replies)
Discussion started by: wrapster
0 Replies
Login or Register to Ask a Question