Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

How to print column by getting user input.?

$
0
0
Hi..

I have data file.. and I could able to print using cat and awk

like this

Code:

cat filename
awk '{print $1 "\t" $2 "\t" $3}' filename

but I want to receive input from user like this

Code:

echo -n " how many columns you want to display : "
read abc

suppose if I give all, it should display all column, and suppose if I give 1,4,5,8,3

it should display only 1st, 4th,5th,8th,3rd column...

How can I do this...

I have one more problem,

I have one script...using for loop for that.. like this
Code:

for file in *.txt ; do
----------
---------
---------
done

if for loop executed successfully, I want to display

Code:

echo -e "Operation successful"
if not I want to display
Code:

echo -e "Check user input,operation unsuccessful"
please go through attached file

Attached Files
File Type: txt input.txt (4.0 KB)

Viewing all articles
Browse latest Browse all 16232

Trending Articles