OS X (Apple)

OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

Text file cleanup

👤 Login to reply

    #1  
Old 01-20-2017
gigagigosu gigagigosu is offline
Registered User
 
Text file cleanup

Hi there,

i do get some text files that i'd lile to clean them up based on following rule: if a line starts with " then remove return (new line, carriage return) before ".

Example, my input text file

Code:
line 1
line 2
"line 3

I'd like this to come as
Code:
line 1
line 2line3

How can i achieve this?


Moderator's Comments:
Text file cleanup Please use CODE tags as required by forum rules!

Last edited by RudiC; 01-20-2017 at 02:48 PM.. Reason: Added CODE tags.
Sponsored Links
    #2  
Old 01-20-2017
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Code:
$ awk '/^"/ { print L substr($0,2) ; L="" ; C=0; next } { if(C) print L ; L=$0 ; C=1 } END { if(C) print L }' inputfile

line 1
line 2line 3

$

I'll need more details on the newline carriage return thing before I can account for that. are ALL your lines \r\n or just some?
The Following User Says Thank You to Corona688 For This Useful Post:
gigagigosu (01-20-2017)
Sponsored Links
    #3  
Old 01-20-2017
gigagigosu gigagigosu is offline
Registered User
 
thank you for your reply, that does work nicely.
after runnign your command i realized that some of my lines start with a space before ", some with ", can you please update the command so it includes lines that start with space followed by "

Thank you!
    #4  
Old 01-20-2017
RudiC RudiC is offline Forum Staff  
Moderator
 
Not sure if this will work on more sophisticated file structures:
Code:
awk '{sub (/\n"/, _)} 1' RS= file
line 1
line 2line 3

For your new request, try
Code:
awk '{gsub (/\n *"/, _)} 1' RS= file


Last edited by RudiC; 01-20-2017 at 02:59 PM..
The Following User Says Thank You to RudiC For This Useful Post:
gigagigosu (01-20-2017)
Sponsored Links
    #5  
Old 01-20-2017
gigagigosu gigagigosu is offline
Registered User
 
thank you both for your help!
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cleanup a log file data every 2 days aix_admin_007 Shell Programming and Scripting 9 10-26-2012 02:14 PM
How to Cleanup Multipathing Tirmazi Red Hat 2 06-22-2011 10:48 AM
Cleanup script tipi Shell Programming and Scripting 2 09-03-2008 02:01 PM
awk/sed/ksh script to cleanup /etc/group file pdtak Shell Programming and Scripting 6 02-28-2008 02:33 AM
Help with cleanup whdr02 Shell Programming and Scripting 2 01-25-2008 02:44 PM



All times are GMT -4. The time now is 04:15 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?