cut command in solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cut command in solaris
# 1  
Old 05-18-2012
cut command in solaris

hello

i am running a shell script on hp unix and getting a file with control m characters through teradata fastexport(file name -fast_export_tmp.txt).

to remove the control m i applied cut command :

Code:
cat  fast_export_tmp.txt|cut -f2 -d'|'>fastexport.txt

i got a perfectely populated file with correct data .





but when i am applying the same process(using cut command over the tmp file) in sun solaris, am getting blank file Smilie .

please help me on this

Last edited by DukeNuke2; 05-18-2012 at 03:51 AM..
# 2  
Old 05-18-2012
That is a useless use of cat, though that's not the problem.

An alternative command you could try:
Code:
awk -F"|" '{ print $2 }' inputfile > outputfile

If that doesn't work, show a sample of the input you have and the output you want.
# 3  
Old 05-18-2012
to remove ^m at the end of lines you can use the command dos2unix
# 4  
Old 05-18-2012
To remove control m, you can simply open the file in vi and do this (I'm assuming you've ^M at the end of each line):
Code:
:%s/<ctrl+v+m>$//g

# 5  
Old 05-18-2012
Hi ,

For removing CTRL ^M character you need to user below commands

For Vi editor
Code:
%s/^M//g

By sed command
Code:
sed 's/^M//g' <filename>

Another way by tr command
Code:
tr -d '\r' <filename>



Hope you are looking for the same.

-pankaj

Last edited by Franklin52; 05-18-2012 at 10:12 AM.. Reason: Please use code tags for data and code samples, thank you
This User Gave Thanks to pankaj_tarale For This Post:
# 6  
Old 05-18-2012
awk command is not working either.

input file :
[|104566918;-1;3324231;-1; ; ;; ;; ; ;09-1CQIBM;;T;2009-06-23 02:00:00; ;2012-04-09 14:56:19
[|104566920;-1;3324231;-1;-1; ;; ;; ;;09-1CQIBM;;P;2009-06-23 02:00:00; ;2012-04-09 14:56:19

---------- Post updated at 01:09 PM ---------- Previous update was at 12:58 PM ----------

Quote:
Originally Posted by pankaj_tarale
Hi ,

For removing CTRL ^M character you need to user below commands

For Vi editor
%s/^M//g
By sed command
sed 's/^M//g' <filename>

Another way by tr command
tr -d '\r' <filename>

Hope you are looking for the same.

-pankaj

Thanks pankaj

i have to remove junk character from the file through a shell script .
and this script runs daily and thus we receive 100 of files .

I assume that we can not use the vi edit in shell script.

can you please tell some other way to remove these junk characters ..

---------- Post updated at 01:19 PM ---------- Previous update was at 01:09 PM ----------

Quote:
Originally Posted by pankaj_tarale
Hi ,

For removing CTRL ^M character you need to user below commands

For Vi editor
%s/^M//g
By sed command
sed 's/^M//g' <filename>

Another way by tr command
tr -d '\r' <filename>

Hope you are looking for the same.

-pankaj
I am getting the correct populated file now .
first i have removed the control m characters and then i applied the awk command to get the correct data
Code:
sed 's/^M//g' test_export2_tmp.txt|awk -F"|" '{print $2}' > fil2.txt

thanks

Last edited by Franklin52; 05-18-2012 at 10:12 AM.. Reason: Code tags
# 7  
Old 05-18-2012
To the OP. You can use sed like everyone has said to remove the ^M at the end of each line.

But you can't just type in ^M. To get the ^M, press <CTRL> and "V" at the same time. Then let go and hit <ENTER>.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

2. UNIX for Dummies Questions & Answers

Cut pid from ps using cut command

hay i am trying to get JUST the PID from the ps command. my command line is: ps -ef | grep "mintty" | cut -d' ' -f2 but i get an empty line. i assume that the delimiter is not just one space character, but can't figure out what should i do in order to do that. i know i can use awk or cut... (8 Replies)
Discussion started by: ran ber
8 Replies

3. Shell Programming and Scripting

Cut Command error cut: Bad range

Hi Can anyone what I am doing wrong while using cut command. for f in *.log do logfilename=$f Log "Log file Name: $logfilename" logfile1=`basename $logfilename .log` flength=${#logfile1} Log "file length $flength" from_length=$(($flength - 15)) Log "from... (2 Replies)
Discussion started by: dgmm
2 Replies

4. UNIX for Dummies Questions & Answers

Need help with Cut command

Hi I am using 'find' on a particular directory which has some subdirectories too,so when I search for .txt files from the parent directory, it gives all files that matches the pattern in the parent aswellas in the sub directories . eg: Iam at /a/b/c where c has many other directories in it ... (7 Replies)
Discussion started by: jagadish_gaddam
7 Replies

5. UNIX for Dummies Questions & Answers

Help with cut command

Hi guys, I have a line of digits with no delimiters (but fixed record length for each fields). for example aaaa1234bbbb field 1 is 4 digit long, field 2 is 4 digit long and so on. I need to cut fields 1 and 3, and while outputting I need a delimiter between the fields. I can cut... (3 Replies)
Discussion started by: Aceform
3 Replies

6. Shell Programming and Scripting

Help with cut command

Gurus, I need help with the cut command : I have a file with garbage charaters at the beginning of each record; but these characters are not of the same length; First record has 3 garbage chars to be removed; rest have 2; If the length was consistent across all the records, I could have... (3 Replies)
Discussion started by: tru_tell
3 Replies

7. AIX

Use of Cut Command

Hi All, Can anyone tell me how to use cut command?I have tried but its not working...Please find the details below : $ cat file1 SlNo. E_ID E_Name Age Dept 1 123 A 20 Electrical 2 124 B 20 Electronics 3 125 C 24 Computer 4 126 D 23 Mechanical ... (3 Replies)
Discussion started by: Puja Sharma
3 Replies

8. Solaris

/usr/bin/cut not working with largefiles on Solaris 10

I have a person running a perl script that is parsing > 2G log files and pipes to cut -d " " -f 1,6,7,8... The script itself is in a nfs mounted home directory. It runs fine when started from a solaris 8 box but fails after about 400 lines when started from the solaris 10 box. The solaris... (1 Reply)
Discussion started by: wottie
1 Replies

9. UNIX for Dummies Questions & Answers

Cut Command

I have a list of files in a directory that I want to check position 2-6 for a string of EPIP or EPCN. I ran the following command but it isn't working correctly: ls EPDa*.*.*.data |cut -c1-30 All it is doing is cutting the file name not what is in the file. Any help would be appreciated. (3 Replies)
Discussion started by: lesstjm
3 Replies
Login or Register to Ask a Question