Get the positional value from first line of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the positional value from first line of the file
# 1  
Old 04-06-2009
MySQL Get the positional value from first line of the file

Hi,

I have one flat file with delimited field as pipe(|) symbol. The file contains header,detail lines. Header is the first line in the file.

I want to read the value for the position from 15 to 18 in first line of the file.

Pls help me to get the value from position 15 to 18 in first(header) line of the file.
# 2  
Old 04-06-2009
You Can do something like this--
Code:
for a single line as header

echo " Hi|Mister|How|Are|You|Doing" | tr -d "|" | cut -c15-18

to raed at a specific position in a file , you can do something like this--
Code:
cat filename | tr -d "|" | sed -n '1p' >newfile
cat newfile | cut-c15-18

Thanks
NT

Last edited by namishtiwari; 04-06-2009 at 10:15 AM..
# 3  
Old 04-06-2009
MySQL Get Positional value from first line of the file

Thanks for your reply.

The file contains signle header row and multiple detail rows.

Is there anyway to get the value(position 15 - 18) from first line of the file without creating new file?

If there is any solution it will really helpful for me.
# 4  
Old 04-06-2009
can try:
Code:
head -1 testfile |cut -c15-18

so if you want to assign it to a variable within another script etc. it would be:
Code:
var1=`head -1 testfile |cut -c15-18`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a file based on positional constraints

I have a list file1 like dog cow fox cat fish duck crowI want to classify the elements of file1 based on constrains applied on file2. Additionally the number of elements (words) in the each line of file2 is not fixed. This is my file2 cow cat fox dog cow fox dog fish crow fox dog cat ... (5 Replies)
Discussion started by: sammy777
5 Replies

2. Shell Programming and Scripting

Positional Update of XML File

Hello, I have a XML file and need to update the data for a specific XML Attribute in the file. I need a Perl or Awk command to look for <INTERCHANGE_CONTROL_NO>000000601</INTERCHANGE_CONTROL_NO> in the XML file and change the first two 0 of the value to 9. For instance ... (4 Replies)
Discussion started by: Praveenkulkarni
4 Replies

3. UNIX for Dummies Questions & Answers

Remove lines in a positional file based on string value

Gurus, I am relatively new to Unix scripting and am struck with a problem in my script. I have positional input file which has a FLAG indicator in at position 11 in every record of the file. If the Flag has value =Y, then the record from the input needs to be written to a new file.However if... (3 Replies)
Discussion started by: gsam
3 Replies

4. UNIX for Dummies Questions & Answers

Positional Parameters

Can someone tell me in more layman's terms what positional parameters are and give a good example? My book again is confusing me. :confused: (1 Reply)
Discussion started by: Straitsfan
1 Replies

5. Shell Programming and Scripting

Split positional flat file.

Hi, I need to split positional flat file, based on value at position 43-45.( in red "410") Example: 12345678907886421689 200920184820410200920020092002007 12345678907886421689 200920184820411200920020092002007 12345678907886421689 200920184820411200920020092002007... (6 Replies)
Discussion started by: meetmedude
6 Replies

6. Shell Programming and Scripting

ls positional parameter

Hi . I am new to Unix. So i have a tough time. we are using Korn Shell. I have a scenario where i have three files namely xxx01,xxx02,xxx03. Now when i write ls xxx*|wc -l output is 3. But then i write `ls $1|wc -l` and pass xxx* as positional parameter (sh yyy.sh xxx*) output is xxx01. other... (1 Reply)
Discussion started by: vasuarjula
1 Replies

7. AIX

ls positional parameter

Hi . I am new to Unix. So i have a tough time. we are using Korn Shell. I have a scenario where i have three files namely xxx01,xxx02,xxx03. Now when i write ls xxx*|wc -l output is 3. But then i write `ls $1|wc -l` and pass xxx* as positional parameter (sh yyy.sh xxx*) output is xxx01. other... (1 Reply)
Discussion started by: vasuarjula
1 Replies

8. UNIX for Dummies Questions & Answers

Positional parameters

I need to get file names from commandline arguments, it may be any no of arguements, Using for loop i got but how do i display it, bcoz $i will give the number i is assigned $$i is not working either $($i), i need the names of the files got in the arguement (2 Replies)
Discussion started by: shalu@ibm
2 Replies

9. UNIX for Dummies Questions & Answers

Positional Parameters

Hello, I am using the Bourne shell. I am trying to understand the concept of positional parameters. I do understand that positional parameters: 1. Are initialized by shell 2. Have a max of 9 parameters ($1 to $9) 3. Have no limit on the number of arguments 4. Can be rearranged... (15 Replies)
Discussion started by: ericelysia
15 Replies

10. Shell Programming and Scripting

Positional Parameters

HPUX11.0/Korn Shell I have an old script that takes in a series of arguments when its called. The script is really more of a common set of functions that gets called by other scripts as needed. I have been asked to make this into a menu driven script to rollout to app support for their use during... (2 Replies)
Discussion started by: google
2 Replies
Login or Register to Ask a Question