Questions tagged [string]

String manipulation: extracting a part of a string, text replacement, formatting to a given width, etc.

Use this tag for questions about string manipulation, especially in but not limited to shell scripts (use or the specific tag for the shell or other language you're using as appropriate).

For questions about batch processing of text files, see . If the string is a file name or path, use in addition to or instead of . For questions about bypassing the interpretation of special characters, see .

797 questions
2
votes
2 answers

How to remove part of a line?

I need to remove part of a line in a group of files. Example line: TRN*1*301444/05-13-20*6549873211~ I need it to be this instead (remove the portion /05-13-20): TRN*1*301444*6549873211~ The forward slash up to the last asterisk need to be removed…
wbl
  • 21
0
votes
1 answer

Loop that replaces a string only once each time after reading a different string

I'm trying to edit a mod that changes regularly (I'm trying to turn all characters into adults), and in some of the files I need to run a script that finds a specific line like "character = yes" and then find the next iteration of "age = {their…
Byron
  • 1
0
votes
2 answers

Find capitalised lowercase string and put before uppercase string

I have a bash script reading names from a webpage as variables, which use the format LASTNAME Firstname: SANCHEZ Rick SMITH Morty VAN SOMETHING Halen However, I need to display each name as Firstname LASTNAME: Rick SANCHEZ Morty SMITH Halen VAN…
0
votes
2 answers

Concatenate strings passed as arguments with null character as delimiter

I'm looking for a CLI tool that takes an arbitrary number of arguments $a, $b, $c, $d, etc., and writes $a"\0"$b"\0"$c"\0"$d to stdout. Is there a standard tool that can do this that I can just use in the beginning of a pipe on the CLI? My…
UTF-8
  • 3,237
0
votes
1 answer

Convert a string to date format

In Unix i have a file which has information like below $ cat date.txt Mon Apr 8 21:00:42 I Need to convert this as 2019-04-09 00:29:22. Example: $ cat date.txt Mon Apr 8 21:00:42 -- expected o/p Mon Apr 8 21:00:42
Ramkumar
  • 113
0
votes
4 answers

How to count the number of apparitions of a character in a string

The main problem: Write a script that determines a path's depth relative to the filesystem's root. The path is received as an argument on the command line. If no argument is received, the current working directory is considered as the path. …
0
votes
1 answer

find and replace string with unique identifying string in multiple files

I'm working on a project where I'm to replace Lorem Ipsum with relevant text in web template files. Unfortunately, it's identical Lorem Ipsum text throughout all files, and the correlation between a screen and its generating template isn't easy to…
user394
  • 14,404
  • 21
  • 67
  • 93
0
votes
1 answer

Pattern Matching and comparison

I have a file with these sentences Today is a holiday May I go tomorrow No Holiday From these I need to find No Holiday, and I need to compare that with another string, like grep "No Holiday"!="Holiday". I don't know the correct query. I am just…
Ammu
  • 11
0
votes
3 answers

Replace substring

Is there any way to replace a string with a char ? Example : I have, 123456789 And, I want to replace all chars from position 3 to position 8 with * , to produce this result 12******9 Is there a way perhaps using sed -i…
-1
votes
1 answer

Space character within conversion specifier

NOW=$(date +%Y_%m_%d.%H:%M:%S) echo "NOW: $NOW" The goal is to replace the . between the d and % character with a space. How is this performed? Replacing the . with the space character produces and error.
gatorback
  • 1,384
  • 23
  • 48
-1
votes
1 answer

Comparing folder name to line from text file

I'm attempting to compare the name of a directory to a line in a text file. However even when the name of the directory and the line in the text file are the same I can't seem to get them to be "equal". #!/bin/bash for dir in…
codedude
  • 101
-2
votes
1 answer

How do I insert a character in front of a string?

For example I have QQQQQ111025 in a middle of a line. Where 1 can be any character numerical or alphabetical. I need to insert 1 in the front of the QQQQQ or I need to replace the QQQQQ with 1. Keep in mind the 025 has to be 025 so simple…