LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2003, 07:13 AM   #1
d-fens
LQ Newbie
 
Registered: Jul 2003
Location: Friedrichshafen, Germany
Posts: 9

Rep: Reputation: 0
shell script - cut off the '^M'



i got a little problem writing a shell-script to parse log-files and write them into a mysql DB.
--
#extract sizes
grep -i '^HTTP' /home/logs/*.log | cut -f10 -d" " >/home/logs/size
--
Thats the problem: -f10 -d" " marks out the last entry in each line where the bytesize is stored. but when i look at /home/logs/size i get:
1234^M
5^M
..
so i get in trouble when later in another script i try to assign those lines to an integer var.

Does anybody know how to cut off the ^M or another solution?

Tnx in advance,
d-fens
 
Old 07-07-2003, 07:38 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If you're not able to "dos2unix" the files, you can strip the CRLF piping it tru "tr" like :
"grep -i '^HTTP' /home/logs/*.log |tr -d "^V^M" | cut -f10 -d" ".
The ^V^M keycombo is literally typing CTRL +V CTRL +M.
 
Old 07-07-2003, 08:11 AM   #3
d-fens
LQ Newbie
 
Registered: Jul 2003
Location: Friedrichshafen, Germany
Posts: 9

Original Poster
Rep: Reputation: 0
Smile

Thanx alot - it worked..
-> And saved my day!

 
Old 07-19-2003, 01:53 PM   #4
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
although a bit late ...but there is a built in script on most unices ...
dos2unix that can be used for the purpose of stripping the ^M characters (which are nothing but the enters on Windows)
 
Old 07-20-2003, 08:37 AM   #5
d-fens
LQ Newbie
 
Registered: Jul 2003
Location: Friedrichshafen, Germany
Posts: 9

Original Poster
Rep: Reputation: 0
yeah, thanks.
after i got it workin and the time-pressure was gone i figured this one out. seems to be definitely the easiest way..
 
Old 07-20-2003, 11:20 AM   #6
2damncommon
Senior Member
 
Registered: Feb 2003
Location: Calif, USA
Distribution: PCLINUXOS
Posts: 2,918

Rep: Reputation: 103Reputation: 103
Use 'flip' with Debian.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
script: 'for' and 'cut' problems YaK. Linux - General 2 11-06-2005 05:49 AM
Shell scripting question about cut JimBass Linux - Newbie 8 10-20-2005 11:24 PM
Cut text from root shell in Knoppix jglidden Linux - General 3 12-17-2003 03:03 PM
How to use cut in Perl script? mimf Linux - General 1 12-01-2003 04:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration