Unable to run Sed in AIX


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unable to run Sed in AIX
# 1  
Old 03-30-2012
Unable to run Sed in AIX

Hi All,

I've wrote a script to truncate newline characters in a text file. Could you please help me in figuring out the issue

Smilie
Code:
for file in $Filelist; do 
echo $file; 
FileName=`basename $file`; 
sed 's/^M//g' $file> "${file}"2;
mv "${file}"2 "${file}"; 
sed '1d' "${file}" >"${file}"1; 
mv "${file}"1 $file; 
sed 's/^$/|/'|tr '\n\r' ' '> "${file}"1
mv "${file}"1 $file; 
done

Moderator's Comments:
Mod Comment Use code tags for code, please.

Last edited by Corona688; 03-30-2012 at 09:21 PM..
# 2  
Old 03-30-2012
What precisely is it doing or not doing, that it's supposed to do, or not do? If the computer can't figure out what you want from the malfunctioning code, neither can we unfortunately. You'll have to say it.

Show the input you have, and the output that you want. I suspect there's more efficient ways to do this.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-31-2012
Hi,

The code is not returning any thing. I've a master file which will contain 100 file names, The script should read file name from a master file and format the file as below

input file

Filename

This
is
a
test
file

Output File

Filename|This is a test file

Thanks in advance
# 4  
Old 04-02-2012
In your spammed topic you pointed out important things you should have before, like this being a Windows text file being read from. I couldn't understand why this didn't work for you, now I do, and can perhaps suggest alternatives.

Working on it.
# 5  
Old 04-02-2012
Code:
#!/bin/sh

# This will let 'read' eat the carriage returns
IFS="$(printf " \r\n\t")"

while read FILE
do
        (       # Read the header, and the blank line
                read HEADER
                read BLANK
                # Print it out without a newline
                printf "%s|" "$HEADER"
                # Let tr handle the rest
                tr -s '[\r\n]' ' '
                # Add a newline to the end
                echo
        # This entire block reads from $FILE, writes to $FILE.1
        ) < "$FILE" > "$FILE.1"
done < masterlist

This User Gave Thanks to Corona688 For This Post:
# 6  
Old 04-03-2012
MySQL

Sorry to Duplicate it.

I had some issues with the code you have supplied. Might be due to the shell changes or AIX. I got the value like

Output File

Filename|
This
is
a
test file

I've tried this and worked fine,

Code:
  for file in Text_file/*
do
   tr -d '\15' < $file> $file.1
   sed '1d'<$file.1> $file.2
   sed -e '1s/$/|/'<$file.2> $file.1
   tr -s '\n' ' ' <$file.1> $file
   rm $file.1
   rm $file.2
done

Thanks a lot
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Unable to run crash utility

Hi I have a system running cat etc/redhat-release Red Hat Enterprise Linux Server release 7.0 (Maipo), and I am trying to check why is crashing a lot of times. I have checked the following files, but with no sucessfull results: ls -lrt *.log -rw-r--r--. 1 root root 29925 Dec 23 2015... (1 Reply)
Discussion started by: fretagi
1 Replies

2. UNIX for Dummies Questions & Answers

Unable to run awk command

hello Don Cragun sir, i am not able to run this command awk 'NR==FNR{if($0~/^>/){i=substr($0,2);getline};a=a $0;next}{print ">" $1 ORS substr(a, $2, $3-$2+1)}' file1 FS=\\t file2 i searched do text you on twitter, facebook but i get no reply from over there so i post here. ---------- Post... (2 Replies)
Discussion started by: harpreetmanku04
2 Replies

3. Shell Programming and Scripting

Unable to run command after ssh

Hello, I am trying to create a ksh script to login to server and collect gather output of some command to troubleshoot some issue. DATE=`date +%b.%d.%Y.%M.%H` echo " Enter emp id to login to server" read Eid Eid=$Eid echo " Enter hostname of the system" read HOST HOST=$HOST... (2 Replies)
Discussion started by: saurabh84g
2 Replies

4. Shell Programming and Scripting

Unable to run function

Hi, I have a separate file with a ksh function in it. When I try to run it, I get an error about permissions: user@~/scripts/functions$ ksh f_fill_testfunc ksh: f_fill_testfunc: cannot open user@~/scripts/functions$ ls -l batch_functions/f_fill_testfunc -rwxr-xr-x 1 user user 1105 Aug... (18 Replies)
Discussion started by: Subbeh
18 Replies

5. HP-UX

Unable to run some commands in HP-UX

Hi All, I want to get %cpu and %memory utilization for a given process id in HP-UX so am using the following commands 1)TOP -p <PID> am getting error message like Quitting top: pset 26323 doesn't exist,but when am using only TOP command without any options its working fine. 2)ps -e -o pcpu... (5 Replies)
Discussion started by: Ramya_Nm
5 Replies

6. AIX

Unable to run a simple threaded program on AIX

Hi, I am unable to run a simple C++ threaded program on the AIX 5.3 platform. It says exec(): 0509-036 Cannot load program ./sendClient because of the following errors: rtld: 0712-001 Symbol __pthread was referenced from module sendClient(), but a runtime definition of the... (6 Replies)
Discussion started by: asutoshch
6 Replies

7. AIX

unable to run at job

Hi All, I m not able to run at job with normal user on AIX system os version is 5300-05-06. I am able to run at job only with root user. When I try to run at job with any other user I am getting error: at: you are not authorized to use at. Sorry. I checked at.deny file, it is... (4 Replies)
Discussion started by: pkatkade
4 Replies

8. Solaris

Unable to run xclock

Hello. I am trying to run xclock on newly built solaris box - These are the steps I followed: # DISPLAY=localhost:0.0 # export DISPLAY # xclock xclock: not found # cd /usr/openwin/bin # ./xclock Error: Can't open display: localhost:0.0 # Please suggest, what am i doing wrong? Thank... (27 Replies)
Discussion started by: panchpan
27 Replies

9. Shell Programming and Scripting

unable to run a script

thi is (10 Replies)
Discussion started by: angelina
10 Replies

10. UNIX for Advanced & Expert Users

exec unable to run via cronjob

Hi , I write a script like this\ and put it under / (root) : ref=88 df -k | grep /cbmdata/00/gdd | tr -d '%' | \ while read a b c d e other do if (( $e >= $ref )) then line=`find /cbmdata/00/gdd -name "LOGS*" |sort -nr |tail -1` # echo $line rm -f $line fi done ... (11 Replies)
Discussion started by: xramm
11 Replies
Login or Register to Ask a Question