PASSING PART OF FILE CONTENT TO VARIABLE


 
Thread Tools Search this Thread
Top Forums Programming PASSING PART OF FILE CONTENT TO VARIABLE
# 1  
Old 10-16-2012
PASSING PART OF FILE CONTENT TO VARIABLE

All,
I have a log file containing lots of data now i want to extract all text between block below(names) without the title or end pattern but only names,
++++START++++
SCOTT TIGER
HENRY PAUL
JARED OTIENO
OMOLLO JA NIGERIA
++++END++++

the names i want to return and store in a variable in my kornshell code.
Any help on this pls?

regards,
# 2  
Old 10-16-2012
Code:
#!/bin/ksh
c=0
names=""
awk '
/[+]END[+]/ {exit};
p==1 {print};
/[+]START[+]/ {p=1};
' infile | while read name
do
  echo $name
  names[$c]=$name
  (( c = c + 1 ))
done
echo ${names[*]}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing a file name to a variable

Below is the command mv AP_FLEXCUBE_INTERFACE10.txt FTPYMNTE_`date "+%Y%m%d%H%M%S" | tr '' ''`.TXT it is changing the file name to a different name according to time stamp dynamically. I want to capture that dynamic file name present in the directory to a variable . After that i want to... (6 Replies)
Discussion started by: sujit das
6 Replies

2. Shell Programming and Scripting

Extract a part of variable/line content in a file

I have a variable and assigned the following values ***XYZ_201519_20150929140642_20150929140644_211_0_0_211 I need to read this variable from backward and stop read when I get first underscore (_) In this scenario I should get 211 Thanks Kris (3 Replies)
Discussion started by: mkris
3 Replies

3. Shell Programming and Scripting

Passing variable from file to Oracle

cat a1 scott robert tom test script : #!/usr/bin/ksh for NAME in `cat a1` do VALUE=`sqlplus -silent "nobody/bobody01@testq" <<END set pagesize 0 feedback off verify off heading off echo off select username from dba_users where username=upper('$NAME'); END` if ; then echo... (3 Replies)
Discussion started by: jhonnyrip
3 Replies

4. Shell Programming and Scripting

Passing variable as a file-Scripting Help

Hi Guys, i have a file where data is in the below format:: data1 data2 data3 data4 data4 data6 my script written as:: #!/bin/ksh cd $1 at now <<END sh $2 END Here i want to pass the values stored in the above file one by one till the end of line. Here if i am doing it as:: (2 Replies)
Discussion started by: Atp3530
2 Replies

5. UNIX for Dummies Questions & Answers

Getting ls content into a file using variable

hi i just cant figure out how can i do this ls -lt > log.txt using $PWD what i mean is how can i get the ls command content into a file using $PWD variable? :confused: (4 Replies)
Discussion started by: chinababy
4 Replies

6. Shell Programming and Scripting

Passing file content as parameter

Hi All, I am passing a file value as parameter to awk command; Par.txt A|B Input.txt A,1 B,3 C,4 D,5 My desired output should be A,1 B,3 (4 Replies)
Discussion started by: kmsekhar
4 Replies

7. Shell Programming and Scripting

passing variable to another file and replacing

Hi all, I have a script in file1 which gets input from the user say variable "TYPE". This variable is present in the other file2. I want to replace the variable in the file2 with the value given by the user and print the file. How can I achieve this task? file1 code echo "Give... (3 Replies)
Discussion started by: Ananthdoss
3 Replies

8. Shell Programming and Scripting

passing variable content to a function

following on from below link https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 i will be using file reading in while loop say for example while read line123 do echo "line read is $line123" insert_funct $line123 done< mysqldump.sql... (6 Replies)
Discussion started by: vivek d r
6 Replies

9. Shell Programming and Scripting

file content as a part of an if-statement

Hello, I have following problem. I have the result of a database request. I preparated the result via sed, etc. as a string in a file. The string in the file is: ($3==1 || $3==2 || $3==3 || $3==4) Now I want to use the String as a command in an if-statement. So I assigned the string to a... (3 Replies)
Discussion started by: Dr_Aleman
3 Replies

10. Shell Programming and Scripting

Variable of Content From Part of Other File

I may not being doing this description justice, but I'll give it a try. I created a mailx script; there will be several messages using the same script where the only difference is the content. So I figured I'd make the content of the message a variable retrieved from a separate file. I have five... (5 Replies)
Discussion started by: royarellano
5 Replies
Login or Register to Ask a Question