I'm writing a script that will take source / destination pathnames and metadata information from a tab-delimited input file, and then perform various directory creation, file moving and renaming, and tagging of files.
I think I have what I need to do the file manipulation in the script - the problem I am having is with the input file, which is being created in Excel on my MacBook.
The basic loop I'm using in the script is:
My input file contains: Source path/filename, Destination path/filename, Date, and Keywords, separated by tabs.
When I save the file in Mac Excel, the lines are terminated with a ^M character on all except the last line, which brings me to my problem. The script above ignores the last line in the input file. Interestingly enough, when I create the exact same file in PC Excel, the final line terminator does come through, and the script handles it fine. Unfortunately (for me), I'm using my MacBook exclusively to develop the spreadsheet, and it looks like I'll have to live with the bug.
My question is - is there a way to modify the script above, so that it will take the last line as input (without the terminator), or can the script check for existence of a final line terminator and add one if needed before executing the loop? My script will be run numerous times against numerous copies of the spreadsheet, so remembering to add it manually isn't going to be very effective.
I suspect the last line not only has no ^M, but no newline as well. Not just bash read, but many shell utilities such as awk and sed can't be depended on to read a last line which has no ending newline.
I suspect the last line not only has no ^M, but no newline as well. Not just bash read, but many shell utilities such as awk and sed can't be depended on to read a last line which has no ending newline.
Fortunately it's easy enough to add it.
Ok - trying to unscramble this...
- first lines make a temp copy of the input file and put a newline character at the end
- next section loops through the file
I'm not clear on what the line '[ -z "$LINE" ] && continue' does. Is it jumping to the 'done' line, which would skip my processing code?
Ok - trying to unscramble this...
- first lines make a temp copy of the input file and put a newline character at the end
- next section loops through the file
I'm not clear on what the line '[ -z "$LINE" ] && continue' does. Is it jumping to the 'done' line, which would skip my processing code?
It would, but only if the line is completely, utterly blank anyway. That's what -z means.
The idea is, if we add an extra newline to a file which doesn't need one, that won't add an extra line -- and an invalid one, at that -- to your processing.
It would, but only if the line is completely, utterly blank anyway. That's what -z means.
The idea is, if we add an extra newline to a file which doesn't need one, that won't add an extra line -- and an invalid one, at that -- to your processing.
Just tried it - looks like exactly what I needed. Thank you!!!!
Hi, I have a rquirement in unix as below .
I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column.
ex:
Input Text file:
1|A|apple
2|B|bottle
excel file to be generated as output as... (9 Replies)
Hi,
I need urgent help with a tab delimited file I am working on.
This is the file :
TTTT|YYYYYYY|jargon-journal|MP0000000UID||"j1, j2, j3"
I need th following output:
TTTT|YYYYYYY|jargon-journal|MP0000000UID||ji
TTTT|YYYYYYY|jargon-journal|MP0000000UID||j2... (8 Replies)
Hi How to make tab delimited file to space delimited?
in put file:
ABC kgy
jkh ghj
ash kjl
o/p file:
ABC kgy
jkh ghj
ash kjl
Use code tags, thanks. (1 Reply)
1. The problem statement, all variables and given/known data:
Hello!
I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below
1. Read in the data file Survey.txt and assign the column values to variables of... (6 Replies)
I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use
cat file | sed 's/|//t/g'
The above command substituted "/t" not tab in the place of pipe.
Sample file:
abc|123|2012-01-30|2012-04-28|xyz
have to convert to:
abc 123... (6 Replies)
Hi Forum
I have a tab delimited file that opens well in Openoffice calc (excel). But when I perform any operation in command line, it reads the file incorrectly. When I 'save As' the same file in office as tab delimited then it works fine.
The file that I think is tab delimited is actually... (8 Replies)
Hi
I am trying to retrieve values from a tab-delimited file.I am using
while read record
value=`echo $record | cut -f12`
done
Where 12 is the column no i want retieve and record is one line of the file.
But it is returning the full record.
Plz help (4 Replies)
Hi all,
I have a file with single white space delimited values, I want to convert them to a tab delimited file.
I tried sed, tr ... but nothing is working.
Thanks,
Rajeevan D (16 Replies)