How to use sed or AWK to separate a string (NOT string in files)

0

How can I separate .sh files into a list?

I have tried:

ls *.sh  | xargs sed 's/\n/ /g' > out.txt

The return of ls *.sh is a long string with '\n' in the middle.

James Bond

Posted 2010-03-11T10:18:45.770

Reputation: 321

Answers

3

You can try to use:

ls -1 *.sh

ayaz

Posted 2010-03-11T10:18:45.770

Reputation: 8 106

1

You don't want ls here: use ls when you want human eyes to see the nicely formatted output, not for when you want to parse filenames as data. Choose one of:

files=$(echo *.sh)

ary=( *.sh ); files="${ary[*]}'

glenn jackman

Posted 2010-03-11T10:18:45.770

Reputation: 18 546

0

I think:

ls *.sh | xargs

will give you want you want: a line with all the .sh files in the current folder.

user3631881

Posted 2010-03-11T10:18:45.770

Reputation: 21