Get line of textfile and store it in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get line of textfile and store it in variable
# 1  
Old 03-15-2010
Get line of textfile and store it in variable

Hi!

I need to do the following:

(1) I wan't to extract a line of a textfile (defined by a numer) and store it into a variable...

(2) ...but I want to cut out a part of the line which is between two tokens and store just this to the variable

Example:
BlaBlaBla Bla2Bla2Bla2 *pPointerOne;
--> So only the Text between '*' and ';' ('pPointerOne') should be stored in the Variable

This is a bit too much for me! Please help!
# 2  
Old 03-15-2010
Code:
echo "BlaBlaBla Bla2Bla2Bla2 *pPointerOne;" | cut -d '*' -f2 | cut -d ';' -f1

Is this what u need ?
# 3  
Old 03-15-2010
Code:
my $str="BlaBlaBla Bla2Bla2Bla2 *pPointerOne;";
  if($str=~/[a-z0-9]+\s+\*([a-z A-Z]+)\;/)
  {
      print $1;
  }

# 4  
Old 03-15-2010
Give that line as a input for the following sed expression,


Code:
result=`sed -r "s/^.*(\*.+;)$/\1/g" <<<"BlaBlaBla Bla2Bla2Bla2 *pPointerOne;"`
echo $result

# 5  
Old 03-15-2010
OK, with your help I go this:

line1=`sed -ne 5p ./Buttons | cut -d '*' -f2 | cut -d ';' -f1`

What I need now, is to replace the '5' by a variable ($couter2)... I don't know how to do this, have problems with the format... Just inserting $counter2 doesn't work... How do I have to do this???

./Buttons is the file where I get the lines from

line1 is the variable where is store the whole output to use later
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with taking variable of for loop in textfile

Hi, I am new to unix/linux scripting. I have a text file, listlib.txt where the content: lib1_23 lib34_a ab_li_lab I need to generate a file (.log) of each cell. I am planning to create a (.csh) script that will have for loop with variable taken from listlib.txt. As for now, i have no... (4 Replies)
Discussion started by: mmaz
4 Replies

2. Shell Programming and Scripting

Bash to match and store line as variable

The bash below loops through a specific directory dir and finds and writes the oldest folder to a variable called $filename. #!/bin/bash # oldest folder stored as variable for analysis, version log created, and quality indicators matched to run dir=/home/cmccabe/Desktop/NGS/test find... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

How to separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :) Say i open some textfile with some example like this. on the table are handy, bread and wine Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this: table plane ... (3 Replies)
Discussion started by: schwatter
3 Replies

4. Shell Programming and Scripting

How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files. all my parameters files are in the same directory, so pick them up with ls *.para >>dirafter that I have a dir file like that: param1.para param2.para etc... I... (2 Replies)
Discussion started by: shadok
2 Replies

5. Shell Programming and Scripting

How to extract more than 1 line in a textfile ?

Hi, I'm starting a little project with a shell script but I'm don't know how to do it. Maybe someone can help me. I have un text file like this : I'd like to do a script who will extract from my file from @ADDLINE1@ to @ADDLINE4@ only and I have no idea how to do this. Any idea ? ... (7 Replies)
Discussion started by: Poulki
7 Replies

6. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies

7. Shell Programming and Scripting

Capturing a number at the end of line and store it as variable

Hello, Would someone guide me on how to write a shell script the would search for a phone no using at the end text file using sed or awk and store it in a varaible or print it. The text file is in this form text or numbers in first line text or numbers in second line . . . Firsname... (6 Replies)
Discussion started by: amuthiga
6 Replies

8. Shell Programming and Scripting

ksh: How to store each output line into a different variable?

Example output: /tmp/generatelines.sh line1 line2 line3 line4 I want each output line assigned to its own variable, ie: "line1" --> $a "line2" --> $b "line3" --> $c "line4" --> $d Is this possible without writing to a temporary file? Thanks (4 Replies)
Discussion started by: ksheller
4 Replies

9. Shell Programming and Scripting

store the first line of a file in a variable

i have to store the files in a folder and assign a variable to the the files. (0 Replies)
Discussion started by: dineshr85
0 Replies

10. UNIX for Dummies Questions & Answers

Read and store each line of a file to a variable

Hi all, I'm quite new to unix and hope that someone can help me on this. I'm using csh. Below is what i intend to do. 1. I stored some data in a file. 2. I intend to read the file line by line and store each line of data into a variable, so that i can used it later. Anyone have any... (4 Replies)
Discussion started by: seijihiko
4 Replies
Login or Register to Ask a Question