Remove newline char from variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Remove newline char from variable
# 1  
Old 05-21-2013
Remove newline char from variable

I have a file ABC.DAT with 2 columns avaialble
Data format :
Code:
XYZ!$#$!120
XXZ!$#$!1000
YYZ!$#$!104

While running the following code :

Code:
FILE_COUNTER=1;
RECORD_CN_FILE_COUNT=$((`wc -l ABC.DAT| cut -f1 -d' '`));
while [ $FILE_COUNTER -le $RECORD_CN_FILE_COUNT ]
do
FILE_NAME=`cat ABC.DAT.DAT| head -$FILE_COUNTER |tail -1 | awk -F '[!][$][#][$][!]' '{print $1}'`
FILE_CNT=`cat $ABC.DAT | head -$FILE_COUNTER |tail -1 | awk -F '[!][$][#][$][!]' '{print $2}'`
DATA_CNT_FILE=`wc -l ABC.DAT| cut -f1 -d' '`;
echo $FILE_NAME','$FILE_CNT','$TOTAL_D_COUNT','$DATA_CNT_FILE > NNN.DAT;
FILE_COUNTER=$(( FILE_COUNTER + 1 ));
done

The last echo is bieng redirected in file gives me an output value with
Code:
XYZ,120
,3


##I get a newline character in the variable $FILE_CNT along with data,how do I remove this newline character from the variable without using SED.

Last edited by Scrutinizer; 05-21-2013 at 01:39 PM.. Reason: code tags
# 2  
Old 05-21-2013
Please use code tags for posting any code fragments or data samples.

Can you briefly explain what exactly you are trying to achieve? It will be better if you can post a sample input and desired output.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Replace the unexpected newline char with space in a Fixed width file

Input eg: Ouput Expected. The #rd line had the unexpted new line, which need to be replaced with space. I was planing to go with checking the length of each line using awk and if the length is less than the defeined limit, (12 in above case) will replace the newline with space. ... (5 Replies)
Discussion started by: deepakwins
5 Replies

2. Shell Programming and Scripting

Remove last newline character..

Hi all.. I have a text file which looks like below: abcd efgh ijkl (blank space) I need to remove only the last (blank space) from the file. When I try wc -l the file name,the number of lines coming is 3 only, however blank space is there in the file. I have tried options like... (14 Replies)
Discussion started by: Sathya83aa
14 Replies

3. Shell Programming and Scripting

Shell to remove a newline char from selected rows in a file.

Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 ... (3 Replies)
Discussion started by: mailme0205
3 Replies

4. UNIX for Dummies Questions & Answers

Remove a newline char from selected rows.

Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 ... (2 Replies)
Discussion started by: mailme0205
2 Replies

5. Shell Programming and Scripting

cutting long text by special char around 100 byte and newline

Regard, How can i cut the text by special char(|) around 100 byte and write the other of the text at newline using Perl. ... (3 Replies)
Discussion started by: Shawn, Lee
3 Replies

6. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

7. Shell Programming and Scripting

Splitting a variable based on newline char

Heeloo all, A weird problem perhaps. May god save others from this problem. I want to print each line from a variable.. the example below should make it clear. smvar="Hello World1 Hello world 2 forgot there I guess" for eachline in $smvar echo $eachline end Whats for... (3 Replies)
Discussion started by: pavanlimo
3 Replies

8. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

9. Shell Programming and Scripting

how to remove all tabs and newline (\n)

how to remove all tabs and newline (\n) from the exicting file (2 Replies)
Discussion started by: pvr_satya
2 Replies
Login or Register to Ask a Question