LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-15-2006, 07:43 AM   #1
shiroh_1982
LQ Newbie
 
Registered: May 2006
Posts: 9

Rep: Reputation: 0
Capturing some data from a file into a variable


I have a file with some values in a tab delimted format

Eg:
'test' contains:

a<tab>b<tab>c<tab>Trk_12345678

now i need to capture this value 'Trk_12345678' into a variable say 'x' and append that value of 12345678 to 12345679 and store is back to a new 'test1' file as :

'test1' contains:

a<tab>b<tab>c<tab>Trk_12345679

Can someone kindly help me on this.I kinda know u have to use commands like sed,cut etc..i jst need some insight of the exact usage.

Thanks.
 
Old 06-15-2006, 08:57 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I am not sure exactly what you are trying to do. Sed or gawk can be used to return particular values from your file, "test". If you are only going to get one such value returned (or don't care about the newlines), you can assign it to a variable as follows:
Code:
x=$(gawk ... test)
x=$(sed ... test)
where the three dots represent the appropriate options and/or script.

You can use "cut" to return particular columns or fields from a file, and if you desire, you can redirect these to a new file.

Perhaps it would be easiest if you reviewed the man pages (e.g. "man sed")
or info pages (e.g. "info sed") and see if you could formulate a more targeted question.
 
Old 06-16-2006, 06:07 AM   #3
shiroh_1982
LQ Newbie
 
Registered: May 2006
Posts: 9

Original Poster
Rep: Reputation: 0
well as I mentioned above I did try reading the commands like cut and sed in the man pages.I was jst lookng at the exact usage.
 
Old 06-16-2006, 06:59 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 70
This would do it if you had a one-line file:
Code:
#!/bin/bash

INPUT=$1
OUTPUT=$2

TRK_PHRASE="Trk_"

let x=$( awk '{ print($4)}' $1 | sed "s/${TRK_PHRASE}//" )

let y=x+1

sed "s/${TRK_PHRASE}$x/${TRK_PHRASE}$y/" $1 > $2
That should get you started.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iwlist vs tethereal in capturing 802.11 wifi ESSID and data rates powah Linux - Wireless Networking 0 11-07-2005 11:21 AM
Capturing FTP data on wireless ravigupta Linux - Wireless Networking 0 04-17-2005 08:24 AM
Capturing raw mouse data pld Linux - Software 4 04-11-2004 09:13 PM
capturing STDOUT to file. tn1681 Programming 5 11-01-2002 12:51 PM
Capturing tty data to a file svaujin Linux - Newbie 2 04-03-2001 10:53 AM


All times are GMT -5. The time now is 08:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration