Sponsored Content
Top Forums Shell Programming and Scripting Specifying IFS delimiter in while loop Post 302977713 by SkySmart on Thursday 21st of July 2016 10:48:27 AM
Old 07-21-2016
Quote:
Originally Posted by RudiC
How about (bash!)
Code:
echo "${ALLMYDATA//#x#/ }" | while read -r line junk; do echo $junk, $line; done

?
this is ideal however, its not portable. some OSes dont have bash..i.e. sunos and aix.

---------- Post updated at 09:30 AM ---------- Previous update was at 09:28 AM ----------

Quote:
Originally Posted by rbatte1
If you are using bash, would you be better with this as your loop?:-
Code:
ALL_MY_DATA=$(sed 's/#x#/ /g' <<< $ALLMYDATA)                    # Replace the three characters with a space all through the record
for LINE in $ALL_MY_DATA
do
   echo $LINE
done

However it seems that you might only want the first field of each row. Is that right?

If so, then you could perhaps work on a variation of:-
Code:
while read LINE
do
   echo "${LINE%%#x#*}"                                          # Trim off everything after the first #x#
done <<< "$ALLMYDATA"

If you are using ksh we can work it out for that too.



I hope that this helps,
Robin
im not only looking for the first field. its just in the example i provided, the first field happened to be the field i was looking for. im going to be interested in all fields.

---------- Post updated at 09:48 AM ---------- Previous update was at 09:30 AM ----------

Quote:
Originally Posted by rbatte1
If you are using bash, would you be better with this as your loop?:-
Code:
ALL_MY_DATA=$(sed 's/#x#/ /g' <<< $ALLMYDATA)                    # Replace the three characters with a space all through the record
for LINE in $ALL_MY_DATA
do
   echo $LINE
done

However it seems that you might only want the first field of each row. Is that right?

If so, then you could perhaps work on a variation of:-
Code:
while read LINE
do
   echo "${LINE%%#x#*}"                                          # Trim off everything after the first #x#
done <<< "$ALLMYDATA"

If you are using ksh we can work it out for that too.



I hope that this helps,
Robin

Code:
ALL_MY_DATA=$(sed 's/#x#/ /g' <<< $ALLMYDATA)                    # Replace the three characters with a space all through the record
for LINE in $ALL_MY_DATA
do
   echo $LINE
done

this seems to work but it appears if the data contains an "x" it gets read of it and replaces it with a space.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

regarding IFS=

hi i am a learner can some explain "export IFS=$(echo "\n\t\a")" i am not able to understand the functionality please help thanks Satya (1 Reply)
Discussion started by: Satyak
1 Replies

2. Shell Programming and Scripting

Preventing whitespace to be a delimiter in a for loop (bash/sh)

Hi, I have a for loop which iterates over a list of strings, separated by whitespace: $ list="1 2 3" $ for i in $list; do echo $i; done 1 2 3 I now want to introduce some strings containing whitespace themselves ... This is straightforward if I directly iterate over the list: $ for... (4 Replies)
Discussion started by: kkkoehne
4 Replies

3. Shell Programming and Scripting

while loop with 3 ifs

im messing up somehwere...and can't seem to clean up the script...for it to work objectives: 1. check for today's file, and sleep 30 secs between retries 2. only allow 5 tries before script should fail. 3. if today's file found, wait 30 seconds for it to process.. code: count=0... (8 Replies)
Discussion started by: sigh2010
8 Replies

4. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

5. Shell Programming and Scripting

How to use IFS in this scenario?

Given the scenario like this, if at all if have to use IFS on the below given example, how it should be used. IFS=/ eg: /xyz/123/348/file1 I want to use the last slash /file1 . So can anyone, suggest me how to pick the last "/" as a IFS. (4 Replies)
Discussion started by: raghunsi
4 Replies

6. Shell Programming and Scripting

While loop and IFS?

Hi, while ; do echo "Please enter " read enter yyyy=${enter:0:4} mm=${enter:5:2} dd=${enter:8:2} result=`validateDate $yyyy $mm $dd` When does the loop keeping repeating till?? till 1 is equal to 1? what does this mean "${enter:0:4}" .The 0 and 4 part?? ... (3 Replies)
Discussion started by: sid22
3 Replies

7. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

8. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

9. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

10. Shell Programming and Scripting

Need to loop file data based on delimiter

My file has data that looks like below: more data.txt I wish to display each string seperated by a delimiter : Expected output: I tried the below but I m not getting every split string on a new line. #!/bin/bash for i in `sed 's/:/\\n/g' data.txt`; do echo -n... (2 Replies)
Discussion started by: mohtashims
2 Replies
All times are GMT -4. The time now is 03:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy