# Shell script request

**URL:** <https://community.unix.com/t/shell-script-request/307652>\
**Category:** Shell Programming and Scripting\
**Created:** [April 2, 2012, 10:34am UTC](https://community.unix.com/t/shell-script-request/307652 "2012-04-02T10:34:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![udayakumar](https://community.unix.com/letter_avatar/udayakumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@udayakumar](https://community.unix.com/u/udayakumar)\
**Post date:** [April 2, 2012, 10:34am UTC](https://community.unix.com/t/shell-script-request/307652/1 "2012-04-02T10:34:47Z")

</div>

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 in AIX.

input file

```nohighlight
Filename

This
is
a
test
file

```

Output File

```nohighlight
Filename|This is a test file

```

Thanks in advance

```nohighlight
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

```

This is doing nothing. I'm not good at sed. Please help.

---

<div class="post-metadata">

**Author:** ![DukeNuke2](https://community.unix.com/user_avatar/community.unix.com/dukenuke2/32/407_2.png) [@DukeNuke2](https://community.unix.com/u/DukeNuke2)\
**Post date:** [April 2, 2012, 10:51am UTC](https://community.unix.com/t/shell-script-request/307652/2 "2012-04-02T10:51:02Z")

</div>

what have you tried? where do you need help?

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/5_5575768a8748004e209b776fc1b2916d.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [April 2, 2012, 12:49pm UTC](https://community.unix.com/t/shell-script-request/307652/3 "2012-04-02T12:49:14Z")

</div>

What Operating System and version do you have? What Shell do you use?

You seem to refer to ^M a lot (which I interpret as intending to mean ctrl/M or carriage-return).  
Is the input file a Microsoft format text file with carriage-return line-feed at the end of each line? Or is this a normal unix text file with just line-feed at the end of the line. Or is this an old MAC format text file with carriage-return at the end of each line?

Does Filename occur at the top of each file called Filename?

---

<div class="post-metadata">

**Author:** ![udayakumar](https://community.unix.com/letter_avatar/udayakumar/32/5_5575768a8748004e209b776fc1b2916d.png) [@udayakumar](https://community.unix.com/u/udayakumar)\
**Post date:** [April 2, 2012, 1:27pm UTC](https://community.unix.com/t/shell-script-request/307652/4 "2012-04-02T13:27:49Z")

</div>

Hi

I'm using bash shell in AIX 6.1  
^M microsoft text  
Yes its a Microsoft format text file with carriage-return line-feed at the end of each line

No the file name I've mentioned in example will be a free test like "Null in a Not Null column" or "0 Length Char". This will be standard in all files.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 2, 2012, 1:31pm UTC](https://community.unix.com/t/shell-script-request/307652/5 "2012-04-02T13:31:10Z")

</div>

Bumping up posts or double posting is not permitted in these forums.

Please read the [rules](http://www.unix.com/misc.php?do=cfrules), which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [April 2, 2012, 1:31pm UTC](https://community.unix.com/t/shell-script-request/307652/6 "2012-04-02T13:31:51Z")

</div>

Duplicate topic, continue [here](http://www.unix.com/unix-dummies-questions-answers/180829-unable-run-sed-aix.html#post302616315).
