Broken line issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Broken line issue
# 1  
Old 06-16-2014
Broken line issue

Hi,

I have a major problem in my source files. I have around 10 source files(around 20 GB).In one of the source files I am getting the broken line issue.My source files needs to be like this

Code:
Sr.No~Ref.No~Address~Acc.No
  1~ABC345~No.2/110~456474
  2~ABC786~4w/54~458695
  3~ABC398~45/67B~748582
  4~ABC984~67/54t~852147

Because of broken line issue, I have getting the source file like this.

Code:
Sr.No~ Ref.No~Address~Acc.No
  1~ABC345~No.2/110~456474
  2~ABC786~4w/54        
  458695        
  3~ABC398~45/67B~748582  
  4~ABC984~67/54t~852147

My source files starts with SR.No Column and its not static.But my ref.no starts with "ABCxyz"..Is there any solution to fix this?

Last edited by Scrutinizer; 06-16-2014 at 04:11 AM.. Reason: code tags
# 2  
Old 06-16-2014
Try:
Code:
awk -F~ '{ORS=NF<4?FS:RS}1' file

# 3  
Old 06-16-2014
Hi,

Can you pls. explain the command....

What is that 1 implies?
# 4  
Old 06-16-2014
In general awk has the form:
Code:
awk '
condition {action}' filename

The action is controlled by the condition. So whenever the condition is true(1), the action is executed.

Here 1 is always true and since no action is specified, it prints the current line by default.
# 5  
Old 06-16-2014
In addition to that: ORS=NF<4?FS:RS means, if the number of fields is less than 4 set the output record separator (ORS) to the field seperator (FS, ~ in this case), otherwise to the input record separator (RS, a newline by default)
This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reading File line by line - Issue

I am trying to read the below file line by line for the below operation i) extract the directory alone and assign it one variable ii) extract the permission available in the line and add comma between the permissions and assign to another variable iii) Finally apply setfacl logic as shown in... (3 Replies)
Discussion started by: sarathy_a35
3 Replies

2. Shell Programming and Scripting

Performance issue - to read line by line

All- We have a performance issue in reading a file line by line. Please find attached scripts for the same. Currently it is taking some 45 min to parse "512444" lines. Could you please have a look at it and provide any suggestions to improve the performance. Thanks, Balu ... (12 Replies)
Discussion started by: balu1729
12 Replies

3. UNIX for Beginners Questions & Answers

Performance issue to read line by line

Hi All- we have performance issue in unix to read line by line. I am looking at processing all the records. description: Our script will read data from a flat file, it will pickup first four character and based on the value it will set up variables accordingly and appended the final output to... (11 Replies)
Discussion started by: balu1729
11 Replies

4. Shell Programming and Scripting

[BASH] read 'line' issue with leading tabs and virtual line breaks

Heyas I'm trying to read/display a file its content and put borders around it (tui-cat / tui-cat -t(ypwriter). The typewriter-part is a 'bonus' but still has its own flaws, but thats for later. So in some way, i'm trying to rewrite cat using bash and other commands. But sadly it fails on... (2 Replies)
Discussion started by: sea
2 Replies

5. Shell Programming and Scripting

awk new line issue, saying string can't contain new line character

Hi , I am doing some enhancements in an existing shell script. There it used the awk command in a function as below : float_expr() { IFS=" " command eval 'awk " BEGIN { result = $* print result exit(result == 0) }"' } It calls the function float_expr to evaluate two values ,... (1 Reply)
Discussion started by: mady135
1 Replies

6. Shell Programming and Scripting

while read LINE issue

Hi, This is the script and the error I am receiving Can anyone please suggest ? For the exmaple below assume we are using vg01 #!/bin/ksh echo "##### Max Mount Count Fixer #####" echo "Please insert Volume Group name to check" read VG lvs |grep $VG | awk {'print $1'} > /tmp/audit.log ... (2 Replies)
Discussion started by: galuzan
2 Replies

7. Shell Programming and Scripting

New line characted issue

Hi Inorder to eliminate new line characters and the empty lines from our data and I used the below syntax : awk '/^/{print ""};{gsub("\"\"", "");printf"%s", $0};END{print ""}' | sed '/^$/d' and eliminated all the new line char and the empty lines in my data. But except the below sample... (10 Replies)
Discussion started by: rbmuruga
10 Replies

8. Shell Programming and Scripting

paste broken pieces of a record into one line

I am working with a file that has some of the records broken into several lines, I need paste the pieces back into one line. All records should start with numeric id, and presently all lines do start with id. The last field of the record is "telephone", so I need to make sure that each line starts... (1 Reply)
Discussion started by: migurus
1 Replies

9. Shell Programming and Scripting

Issue in reading file line by line

I have a file something like: a &nbsp&nbsp&nbsp b c &nbsp&nbsp d sdfsdf &nbsp&nbsp f f &nbsp f f &nbsp fffff dfdf Now when i read it as while read line do echo $line done< file I get the o/p as a b c d sdfsdf f f f f fffff dfdf (5 Replies)
Discussion started by: Shivdatta
5 Replies

10. Shell Programming and Scripting

end of line issue

Hello, I am getting few text files with no EOF ( or end-of-line ) which i need to fix using a command so that i can include it in a script. Now i'm fixing this issue by opening the file in "vi" editor and adding last line. e.g., server1#wc -l temp.txt 9 temp.txt server1#cat ... (6 Replies)
Discussion started by: prvnrk
6 Replies
Login or Register to Ask a Question