differnce between two commands

sam2929
sam2929 used Ask the Experts™
on
What is difference between this two commands.

info_file_name=`echo $i | cut -d "/" -f 7`
 
info_file_name=`echo $i | cut -d "/" -f 6`
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:
The field being reported.
I.e.
/some/Pah/to/file/of/interest/as/input
The first will return input while the second will return as.

Cut parses the input data based on '/'

Author

Commented:
Not sure what you said can you give an example please3
Distinguished Expert 2017

Commented:
If I='/some/Pah/to/file/of/interest/as/input'
When you run each command which parses the contents of the variable i,
The first one is interested in the 7th element which from the example will be as
The second command which is interested in the 6th element which in the anode example will be interest

Seems ihave miscounted.

The best way I find what commands do is to select the input and see what the results.

Cut -d "/" will break the string based on the existence of every '/' in the string. As a list of items separated by /




What is unclear.

It is easier to explain when your concept or understanding of the issue is included.
Commented:
info_file_name=`echo $i | cut -d "/" -f 7` - stores  the 7th Field from "/" in the given input(i) to info_file_name variable

info_file_name=`echo $i | cut -d "/" -f 6` . - stores  the 6th Field from "/" in the given input(i) to info_file_name variable

eg: -
i="/1/2/3/4/5/6/"
then your results will be
info_file_name=`echo $i | cut -d "/" -f 7` --> 6
info_file_name=`echo $i | cut -d "/" -f 6`  --> 5
Distinguished Expert 2017

Commented:
Unfortunately, it seems I double miscounted as the above
The first / separates field number 1 from field number 2
The second, separates field 2 from 3 etc.

If the string is 1/2/3/4/5/6/7/8
When passed through cut -d '/' -f 7 returns 7
-f 6 will return 6

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial