0

There is a file with this simple content:

projectA-app1
projectA-app2
projectA-app-mobile
projectB-app1

Now I need to get every application name into one line (removing line breaks)

apps=$(cat file.txt| tr -s '\n' ' ')

but I also need to remove all applications, which are ending with -mobile. How do I do that?

The result of this example should be

projectA-app1 projectA-app2 projectB-app1
2
  • 1
    Uh? echo $(grep -v "-mobile$" file.txt| tr \\n \ ) Commented Jul 15, 2024 at 12:47
  • Or grep -v "-mobile$" file.txt|xargs Look for xargs about merging lines Commented Jul 15, 2024 at 12:51

1 Answer 1

1

You could reverse grep on mobile$ and then pass the result to tr:

grep -v -E 'mobile$' bla | tr -s '\n' ' '

You could also combine these 2 into a signle command:

awk '!/mobile$/ { printf "%s ", $0 } END { print "" }' bla

projectA-app1 projectA-app2 projectB-app1
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.