Need help in a line formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in a line formatting
# 1  
Old 02-16-2009
Need help in a line formatting

i have a script that check for a file called TNS.txt.I need little help in formatting

TNS.txt
Code:
0001804026

what i want is whenever there is space after the digit it should be rejected or should not be taken into account.

TNS.txt with space:
Code:
0001804026[space]

wc -c 
11

The below command is not working:The result should be 10
Code:
0001804026[space]

cat TNS.txt | grep -v "^$" | wc -c
11

How to ignore spaces in the same line ?

Last edited by ali560045; 02-16-2009 at 02:36 AM..
# 2  
Old 02-16-2009
This might help you

Code:
$ echo "0001804026" | awk -F "" '{print NF}'

# 3  
Old 02-16-2009
Hope this helps:

Code:
sed "/  *$/d" TNS.txt

# 4  
Old 02-16-2009
jaduks and angheloko, the OP wants to get rid of the trailing space. One way, assuming you have only 1 column in your file:

Code:
awk '{print $1}' file > newfile

Regards
# 5  
Old 02-16-2009
Quote:
jaduks and angheloko, the OP wants to get rid of the trailing space. One way, assuming you have only 1 column in your file:

Oh, my bad. I misinterpreted because of this line. I though that the "whole" line should be ignored. Sorry man :P


Quote:
what i want is whenever there is space after the digit it should be rejected or should not be taken into account.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Issues formatting output of two commands in a single line.

I wish to generate output of two commands in the same line separated by a single white-space. Below is my command and output in the same line. ls -ltr fname1.out | awk '{$2=$4=$5=x; print}' | tr '\n' '\t' | tr -s ' '; cksum<fname1.out | cut -d' ' -f1 Output: -rw-r--r--. root Aug 26 16:57... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

Formatting File having big single line into 95 Char Per Line

Hi All, I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end. Before:- File Name:- File1.dat 102 121340560... (10 Replies)
Discussion started by: lancesunny
10 Replies

5. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

6. UNIX for Dummies Questions & Answers

Formatting Multiple fields on 1 line to multiple rows

I'm trying extract a number of filename fields from a log file and copy them out as separate rows in a text file so i can load them into a table. I'm able to get the filenames but the all appear on one line. I tried using the cut command with the -d (delimiter) option but cant seem to make it... (1 Reply)
Discussion started by: Sinbad-66
1 Replies

7. Shell Programming and Scripting

Need a little help with bash line formatting...

Hi there, suppose I have a line that looks like this: and I want it to look like that: The first line is already the output of a long expression with a lot of piping and formatting with awk etc., but now I'm somehow stuck with the rest. Can you give me a clue how to achieve it? Thanks for... (3 Replies)
Discussion started by: RaginRob
3 Replies

8. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

9. Shell Programming and Scripting

Formatting a text file to get data in exact line by line

I have my data something like this SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430693 07/01/2009 05:16:40 FR SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430746 07/01/2009 05:18:05 FR I want the output as follows.... (1 Reply)
Discussion started by: rdhanek
1 Replies

10. UNIX for Dummies Questions & Answers

Formatting a line of data into columns

Hi all, I'm a little stuck with a data file I've been collecting data in. The file contains one field of data running continuously down the file and I can't work out how to format the data into three columns. This is a mock up of the file: Each r# is a random number and varies in length, this... (3 Replies)
Discussion started by: nistleloy
3 Replies
Login or Register to Ask a Question