Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
How to remove all instances of a string from output in linux terminal commands

This command almost does everything I am needing

cat /etc/passwd | cut -f6- -d : | sort | uniq 

but I can't figure out how to sort out a specific string

I need to remove "/remove/this" from any line where it occurs and I need the lines of text not to be broken up for 1 word per line.

The purpose of the command is List all of the shells used by at least one user on the system, without duplicates.

Wold appreciate any input.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use sed. When the pattern you are looking for contains /, you should use a different separator character. I find : quite readable.

cat /etc/passwd | cut -f6- -d : | sort | uniq | sed s:/remove/this::

Since sed will change some lines, it's better to move sort + uniq to the end of the pipeline. sort -u combines both programs.

cat /etc/passwd | cut -f6- -d : | sed s:/remove/this:: | sort -u
over 4 years ago · Santiago Trujillo Report

0

You can use a single awk command for that:

awk -F: '{sub(/\/remove\/this/, "", $NF);a[$NF]} END{for(i in a){print i}}' /etc/passwd

-F: splits the line by :.

The first block runs on every line of input while sub(/\/remove\/this/, "", $NF) removes the string from the last column and a[$NF] creates and index for every shell found in passwd. Obviously if the index already exists, it will not get created again. Doing so we dedup the data.

At the END of input we are iterating trough the array a and print every index: {for(i in a){print i}}

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!