Assiging to a variable after cutting from the input line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assiging to a variable after cutting from the input line
# 1  
Old 09-24-2014
Assiging to a variable after cutting from the input line

Hi all,

I am reading from the file having entries like below
Code:
 
111.ABC.POT
6477.YHT.OIT

Now I need to read each line and cut each line seperated by dot and print into the file .

I tried below and it is not working . Please help
Code:
while read READLINE
do
     eval LINE=${READLINE}
     echo $LINE
     Field5=`echo $LINE|cut -d. -f1`
     echo "${Field1} ,${Field2},${Field3},${Field4},${Field5},${Field6}" > FINAL2.txt
done < FINALFILE.txt

Thanks
DJ


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-24-2014 at 09:20 AM..
# 2  
Old 09-24-2014
I am slightly confused as to what you are trying to do.

Can you please provide some sample output?
# 3  
Old 09-24-2014
+ please use code tags
# 4  
Old 09-24-2014
Quote:
Now I need to read each line and cut each line seperated by dot and print into the file .

I tried below and it is not working .
How can you want to cut line separated by dots when your file sample has not cases of such...
As of post#2 What you gave us and explained is far from being clear, especially when you have not given a example of expected output so we can figure out what you ment
I am dubious looking at your code...
# 5  
Old 09-24-2014
Maybe you can set IFS to split the file during reading, then you do not need cut.
For example, read FINAL.txt, echo the new lines, and redirect the whole loop to FINAL2.txt
Code:
while IFS="." read f1 f2 f3
do
  # compose a new line and print it
  echo "$f1.$f2.$f3.$f1"
done < FINAL.txt > FINAL2.txt

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cutting all xml tags out of a line

I would like search and find a word (easily identified by 'key') from an xml file and then cut all of the tags out of the resulting line (anything between a < and a >) and display the remaining material. I am running Debian and mksh shell. dictionary.sh: #!/bin/sh key='key="'$1'"><form'... (3 Replies)
Discussion started by: bedtime
3 Replies

2. Shell Programming and Scripting

Cutting commas after the second occurrence in a line

Hello everyone, I am manipulating a large CSV file and am trying to read it into a program and started running into trouble. The have manually edited the file trying to make it correctly run through the program and have made progress. However, I am know stuck with an issue involving too many... (3 Replies)
Discussion started by: tastybrownies
3 Replies

3. Shell Programming and Scripting

Cutting a string and storing it in a variable

Hello I have a script: path=test1 echo "${path%?}" till this the program is successful in deleting hte last character i.e. "1" and displays an output --> test. After this how can i save this output to another variable. (2 Replies)
Discussion started by: Kishore920
2 Replies

4. Shell Programming and Scripting

Cutting a part of line till delimiter

here are the few scenarios... isoSizeKB text NOT NULL, reserved1 varchar(255), KEY `deviceId` (`deviceId`) `d5` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `dHead` enum('HistoryInfo','Diversion') COLLATE utf8_unicode_ci, `ePR` int(11) DEFAULT '0', PRIMARY KEY (`id`) ... (7 Replies)
Discussion started by: vivek d r
7 Replies

5. Shell Programming and Scripting

Input two variable on single line

Can we input two variable on single line that separate by space example user input "list jpg" it will list all jpg files in current directory (3 Replies)
Discussion started by: guidely
3 Replies

6. Shell Programming and Scripting

Input variable in command line

i have this script that reads a file "listall_101111" where 101111 varies. awk '{print $0,$1}' listall_101111 | sed -e 's/\(.*\).$/\1/g' | awk '{print $6,$2,$3,$4,$5}' | sort -nrk5 | nawk 'NR==1{m=$5;a++;b=(b)?b:$0;next}$5==m{a++;b=(b)?b:$0}END{for (i in a){print b,a}}' | grep -v ^LG | sort... (4 Replies)
Discussion started by: aydj
4 Replies

7. UNIX for Advanced & Expert Users

Bash shell: Cutting pasting only parts of the name of a directory into a variable

I have a script in a directory and want to search the directory before like follows: i=0 for file in ../HN_* do echo $file ((i+=1)) echo $i done Currently I get following output: ../HN_2 1 ../HN_3 2 (2 Replies)
Discussion started by: ABE2202
2 Replies

8. Shell Programming and Scripting

Cutting characters in a variable

I have a variable var which contains "ABCDEFDH" Now I have to remove the first 4 characters that is "ABCD" so my variable should contain only "DEFH" plzz tell me how to do that . i am using bash shell (1 Reply)
Discussion started by: cynosure2009
1 Replies

9. Shell Programming and Scripting

Cutting columns starting at the end of each line...

Hi Guys, Can you help me with a sed or a csh script that will have an output from the input below. Cutting the columns starting from the end of the line and not from the start of the line? Sample1 - The underscore character "_" is actually a space...i need to put it as underscore here coz... (2 Replies)
Discussion started by: elmer1503
2 Replies
Login or Register to Ask a Question