Format output issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format output issue
# 1  
Old 10-19-2011
Format output issue

Dear Friends,
Need your help.

Code:
$cat input.txt
            TITLE
                       Date:01-01-2011
		       Day: Friday
Details		Particulares           Qty
$
$
$
$
$
$more test.sh
cat input.txt | while read line
do
echo "${line}"
done
$
$
$
$sh test.sh
TITLE
Date:01-01-2011
Day: Friday
Details		Particulares           Qty
$
$

However we want it to be like original file with spaces. Here in our script space before "TITLE", "DATE", "Day" is ignored.

Please help.
Anu
# 2  
Old 10-19-2011
what's wrong with simply using cat <somefile> ?
# 3  
Old 10-19-2011
I suppose the OP needs to apply some logic while processing the file content (i.e. and this is only an example).

To the OP, most probably you don't need cat at all in this case:

Code:
while IFS= read -r; do 
  printf "%s\n" "$REPLY"
done < infile

1. Some shells doesn't provide read -r (so you'll need to remove the -r).
2. Some shells raise an error if read is used without an explicit argument (varname), in that case you should use one.

Last edited by radoulov; 10-19-2011 at 08:53 AM..
# 4  
Old 10-19-2011
not sure how you've managed to interpret so much from such a vague request.....
and your answer is riddled with caveats, i recommend the requester restate the requirement in the name of clarity.
# 5  
Old 10-19-2011
Quote:
Originally Posted by munkeHoller
not sure how you've managed to interpret so much from such a vague request.....
[...]
I suppose it's just because it's hard to believe that someone will ever need a code like that.

Quote:
and your answer is riddled with caveats
[...]
Could you be more specific?
# 6  
Old 10-20-2011
Quote:
Originally Posted by radoulov
I suppose it's just because it's hard to believe that someone will ever need a code like that.



Could you be more specific?
Yes, it may be hard to believe (and 100% with you on that), in which case I will either ignore the request or ask the submitter to restate removing ambiguity.

Quote:
1. Some shells doesn't provide read -r (so you'll need to remove the -r).
2. Some shells raise an error if read is used without an explicit argument (varname), in that case you should use one.
I think giving answers with the likes of the above is asking for trouble, simply give an example that works, let the submitter try them out. if you are being specific, ie command XXXX only tested/works on OS zzzz version xxxx and ....., then don't answer, ask the submitter for clarifications.

all that said, isn't great being able to help - i love it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Format issue

I was trying to copy the file content of program from server to other server you ctrl+c. once after the pasting in the other server the file alignment is getting changed. since I don't have scp permission. I am getting aligment improperly. wat needs to be done to make the format ccorrecltly as... (5 Replies)
Discussion started by: k.keerthi2005
5 Replies

2. Shell Programming and Scripting

Perl format issue

Input : day :15 and count -100 printf ("%6.6ld %10.10s %s\n",day,count) any idea what would be the format it will be. (3 Replies)
Discussion started by: ramkumar15
3 Replies

3. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

4. Shell Programming and Scripting

File format issue

Hi All, In unix is there any command to format the file in exact order.I have a file which there is no order in the fileds, I need to order it. Its a dat file wrong format TDEAIG36533827CB1210004241 EUR20130610BL1300351 refers to CB|CCI|A|A|C|R|T 246.76 ... (1 Reply)
Discussion started by: nag_sathi
1 Replies

5. Shell Programming and Scripting

to replace Date format issue

Hi, I have the below data in a file in one of the path, 101 02100002111406893401207310900A094101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 5200xxxxxxxxxx D18000_1 CCDXXXXXXX JUL 31201207 1140689340000001 622113010547999999999003 000333333334RE ... (1 Reply)
Discussion started by: Ramyajiguru1
1 Replies

6. Shell Programming and Scripting

"links -dump" output format issue

Hi All, I tried searching a lot about this but to no avail. I have a HTML file. I used links -dump file_page.html > text_html.txt What the above command gave me was a filtered text from the HTML file with tags removed. Now, the the output from the above command looked something like this:... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

7. Shell Programming and Scripting

Dynamic output file generation using a input text file with predefined output format

Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has... (1 Reply)
Discussion started by: hudson03051nh
1 Replies

8. Solaris

Duplex Script - output format issue.

Hi Gurus, I had downloaded the below script from the net and used it to get the Link and duplex settings in my Sun servers. In all except one(Sol-5.10 on X86) i am getting output format like below: root: /var/ADMIN/bin/speed_duplex.sh Interface Speed Duplex --------- ... (2 Replies)
Discussion started by: Hari_Ganesh
2 Replies

9. Shell Programming and Scripting

capturing output from top and format output

Hi all, I'd like to capture the output from the 'top' command to monitor my CPU and Mem utilisation.Currently my command isecho date `top -b -n1 | grep -e Cpu -e Mem` I get the output in 3 separate lines.Tue Feb 24 15:00:03 Cpu(s): 3.4% us, 8.5% sy .. .. Mem: 1011480k total, 226928k used, ....... (4 Replies)
Discussion started by: new2ss
4 Replies

10. UNIX for Dummies Questions & Answers

File Format issue: Output of sqlplus

Hi, I am using a query like below in my shell script : { { echo "set echo off" echo "set head off" echo "whenever sqlerror exit -1; select NUMBER ||','|| FNAME ||','|| LOC ||','|| ... (2 Replies)
Discussion started by: deepakgang
2 Replies
Login or Register to Ask a Question