Text file cleanup

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 01-20-2017
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:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 01-20-2017 at 03:48 PM.. Reason: Added CODE tags.
# 2  
Old 01-20-2017
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?
This User Gave Thanks to Corona688 For This Post:
gigagigosu (01-20-2017)
# 3  
Old 01-20-2017
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
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 03:59 PM..
This User Gave Thanks to RudiC For This Post:
gigagigosu (01-20-2017)
# 5  
Old 01-20-2017
thank you both for your help!
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
RPM Repo Cleanup geoeldsul UNIX for Advanced & Expert Users 2 12-15-2017 03:04 PM
Extracting lines from a text file based on another text file with line numbers evelibertine UNIX for Dummies Questions & Answers 1 12-11-2012 04:39 PM
Cleanup a log file data every 2 days aix_admin_007 Shell Programming and Scripting 9 10-26-2012 03:14 PM
Converting a text file with irregular spacing into a space delimited text file? evelibertine UNIX for Dummies Questions & Answers 5 09-05-2011 12:47 PM
How to Cleanup Multipathing Tirmazi Red Hat 2 06-22-2011 11:48 AM
Table Cleanup Script moe458 UNIX for Advanced & Expert Users 3 10-12-2010 11:33 AM
Cleanup between parenthesis msalam65 Shell Programming and Scripting 3 03-01-2010 12:15 AM
how can I bcp out a table into a text file including the header row in the text file shilpa_acc Shell Programming and Scripting 0 07-21-2009 07:24 AM
cleanup $PATH with awk doc_symbiosis Shell Programming and Scripting 17 06-17-2009 11:34 AM
/home cleanup itik Solaris 1 03-31-2009 06:31 PM
Cleanup script tipi Shell Programming and Scripting 2 09-03-2008 03:01 PM
awk/sed/ksh script to cleanup /etc/group file pdtak Shell Programming and Scripting 6 02-28-2008 03:33 AM
Help with cleanup whdr02 Shell Programming and Scripting 2 01-25-2008 03:44 PM
Login ID cleanup MILLERJ62 AIX 1 05-12-2006 05:20 AM
sendmail cleanup thomi39 UNIX for Dummies Questions & Answers 1 02-23-2006 09:48 AM
All times are GMT -4. The time now is 02:15 AM.

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





Not a Forum Member?
Forgot Password?