0

Shell scripting: I have below input file Contents of file1

-bash-4.2$ cat file1
sample.1.17.10.tar
test.1.17.10.tar
work.1.17.1.0.tar

Need to get output as below

From : > cat file2

    sample
    test
    work

From :>cat file3

1.17.10
1.17.10
1.17.10

It should generate two files by stripping the name and value as mentioned

5
  • Are you expecting output of three files above into one file? or you are trying to concat content of all tar files into file or you just need files name? Commented Jan 27, 2020 at 10:00
  • I have input as file1 -> output should be in file2 and file3 Commented Jan 27, 2020 at 10:07
  • I just need the file names. not the content Commented Jan 27, 2020 at 10:08
  • You just need the names? You already have them, they are file2 and file3 surely? Commented Jan 27, 2020 at 10:18
  • Don't you want 1.17.1.0 generated from work.1.17.1.0.tar ? Commented Jan 27, 2020 at 10:47

1 Answer 1

1

Cut and Rev Used as per the example.

$ cat test.test
sample.1.17.10.tar
test.1.17.10.tar
work.1.17.1.0.tar

# For Version
$cat test.test | rev | cut -d"." -f2-  | rev | cut -d"." -f2-  > file1
$ $ cat file1
1.17.10
1.17.10
1.17.1.0

# For Filename
$ $ cat test.test | cut -d'.' -f 1 > file2
$ cat file2 
sample
test
work

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.