Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 07:21 PM
08-29-2007 07:21 PM
I have a comma seperated file. The second field in it is a description field.
But has new line character within the field.
I want the new line character to be removed so that the description field comes in the same line.
For eg: In the file if it is:
10000,"Today
is a holiday"
I want it to be
10000,"Today is a holiday"
Please help..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 08:22 PM
08-29-2007 08:22 PM
SolutionOr any line with a " is mismatched?
If the lines are always broken in pairs, then you could possibly use sed. But if you have to check, you need awk:
awk '
{
inx = index($0, "\"")
if (inx != 0) {
save = $0
getline
print save, $0
next
}
}' file
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 08:35 PM
08-29-2007 08:35 PM
Re: Sed??
Only some lines have this problem. Probably a search for mismathced " will do in a line..
how do we accomplish tat?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 08:52 PM
08-29-2007 08:52 PM
Re: Sed??
If all lines are broken use edit file with vi editor, enter :g/./join
Regards
Marcin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 09:05 PM
08-29-2007 09:05 PM
Re: Sed??
This assumes that the second field has quotes, not the first nor any other.
awk '
{
inx = index($0, "\"")
if (inx != 0) {
rest = substr($0, inx + 1) # after quote
inx = index(rest, "\"")
if (inx == 0) { # mismatched
save = $0
getline
print save, $0 #join lines
next
}
}
}' file
I suppose if you had an arbitrarily complex case you could set the delimiter to ", then if the number of fields was even, then join lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 09:11 PM
08-29-2007 09:11 PM
Re: Sed??
:v/^[0-9]/-1j
and only broken line will be connected
Regards
Marcin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 09:57 PM
08-29-2007 09:57 PM
Re: Sed??
:v/^[0-9]/-1j
>and only broken line will be connected
I'm at a loss on how to get that to work and why it would work.
It seems you are executing the ex(1) visual command from the vi ":" prompt??
Or did you mean "g" instead of "v"?
Ah, you're using a foreign devil vim instead of vi. And "v" did work but I still don't know why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 10:17 PM
08-29-2007 10:17 PM
Re: Sed??
I using standard hp-ux vi.
And there is no mistake with "v", "v" - inverts the search, ex. ":v/./d" = ":g/^$/d" (delete all empty lines)
Regards
Marcin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 11:01 PM
08-29-2007 11:01 PM
Re: Sed??
Hmm, it works now. I don't know what I did to get it to fail. ??
>And there is no mistake with "v", "v" - inverts the search,
You can only find it in ex(1) if you know v is related to g or global. They don't list it alphabetically under v. And don't have flashing red lights. :-(
It is in the Abbreviations box.
Thanks for the info. Though if you used g!, it would have been easier to figure it out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2007 11:18 PM
08-29-2007 11:18 PM
Re: Sed??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 12:10 AM
08-30-2007 12:10 AM
Re: Sed??
perl -pe 'if (!/^.*?,".*?"/ && !eof) { chomp; $_ .=<> }' old > new
To check any field (including 2), leave the begin-of-line anchor of:
perl -pe 'if (!/,".*?"/ && !eof) { chomp; $_ .=<> }' old > new
fwiw,
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 12:50 AM
08-30-2007 12:50 AM
Re: Sed??
Another Perl:
# perl -ni.old -e 'if (!m/"$/) {chomp;print $_." "} else {print}' file
This will also update your file in situ (in place) leaving an unmodified copy as "file.old".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 01:47 AM
08-30-2007 01:47 AM
Re: Sed??
# sed 'N;s/\n/ /p' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 09:40 AM
08-30-2007 09:40 AM
Re: Sed??
# sed 'N;s/\n/ /p' file
This was rejected as not every line had the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 09:52 AM
08-30-2007 09:52 AM
Re: Sed??
>do in a line..
Good point Dennis...hadn't read the entire thread until now and based on requirements try the construct below which might be what Rinky's looking for:
# sed '/"$/!N;s/\n/ /p' file
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 03:14 PM
08-30-2007 03:14 PM
Re: Sed??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2007 03:15 PM
08-30-2007 03:15 PM