logo
down
shadow

Extract part of a file name in bash


Extract part of a file name in bash

By : user2948852
Date : November 15 2020, 06:54 AM
Hope this helps I have a folder with lots of files having a pattern, which is some string followed by a date and time: , Use sed with extended-regex and groups to achieve this.
code :
cat filelist | sed -r 's/(.*)[0-9]{8}_[0-9][0-9]-[0-9][0-9].[0-9][0-9].csv/\1/'
ls mydir/*.csv | sed -r 's/(.*)[0-9]{8}_[0-9][0-9]-[0-9][0-9].[0-9][0-9].csv/\1/'


Share : facebook icon twitter icon
bash: a more effective way to search strings in a file and extract part of strings

bash: a more effective way to search strings in a file and extract part of strings


By : jagxe94
Date : March 29 2020, 07:55 AM
Does that help I like @JohnKugelman's approach, but it can be improved: use colon and quote as the field separators:
code :
while IFS=':"' read -ra fields; do 
    case ${fields[0]} in 
        AGE)  age=${fields[1]}  ;; 
        NAME) [[ ${fields[1]} == "2,0," ]] && name=${fields[2]} ;; 
    esac
done < file
read age name < <(
    awk -F '[:,]' '
        $1 == "AGE" {printf "%s ",$2} 
        $1 == "NAME" && $2 == 2 && $3 == 0 {printf "%s ",$NF} 
        END {print ""}
    ' filename 
)
Extract part of a string in BASH

Extract part of a string in BASH


By : user3618452
Date : March 29 2020, 07:55 AM
This might help you I have a puzzle to solve which I could not do on my own. I believe it may be a simple one for others. I was trying to solve in a one liner. , Using BASH string manipulations:
code :
s='Tree-Forest Vegetable-fruit-Garden Fish-Frog-Ponds Chicken-Duck-Farm'
echo "${s%-*}"
Tree-Forest Vegetable-fruit-Garden Fish-Frog-Ponds Chicken-Duck
sed 's/-[^-]*$//' file
Tree
Vegetable-fruit
Fish-Frog
Chicken-Duck
in bash shell: extract part of the output of a command and output to file

in bash shell: extract part of the output of a command and output to file


By : Davis Li
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Say I run "mount" on Bash, I get something like this: , For a line that matches "mounted by", print column 3:
code :
mount | awk '/mounted by / { print $3 }'
Extract part of filename while looking for file using bash

Extract part of filename while looking for file using bash


By : Oskar
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , No, there isn't a simplified version. find is a specialized tool -- it doesn't implement arbitrary text-processing support.
A version focused on correctness would actually be even more verbose, looking something like:
code :
while IFS= read -r -d '' filename; do
  base=${filename%.xml}
  echo "Filename $filename without its extension is $base" # put your actual command here
done < <(find . -name '*.xml' -print0)
Find a line of a file, extract part of it and replace in the same place in Bash

Find a line of a file, extract part of it and replace in the same place in Bash


By : user3158231
Date : March 29 2020, 07:55 AM
should help you out It would be easier using sed (I use GNU sed, to be specific) to achieve the result:
code :
sed -E '/execution time/s/.*\(([0-9]*) mseconds\)/\1/'
Related Posts Related Posts :
  • What does it mean by code holding semaphore can be preempted
  • Does LD_LIBRARY_PATH really cause inconsistencies?
  • "lsof" shows a file as (deleted) but I can still see it in file system
  • Linux file deleted recovery
  • Exchange columns in bash
  • How to set max file size in Linux CeNTOS to server.log
  • Regular expressions: Search a word and append a new word at the end of the line
  • Compress a set of log files in a folder depending on number of files
  • unexpected behavior of linux malloc
  • relation between init and bash terminal process
  • Matlab VideoReader codec error?
  • How to catch the L3-cache hits and misses by perf tool in Linux
  • Executable Deleting Itself on linux
  • How to change the apache httpd port for serving files
  • Installing Patches in linux
  • Comparative analysis between libkvm on linux and NetBSD
  • How to join multiple txt files into based on column?
  • setting LINK variable in Makefile generated by qmake (5.0)
  • Automake - difficulty with installing version 'automake-1.14.1'
  • How to use Linux Network Namespaces for per processes routing?
  • How can I write a Gruntfile with different shell command behaviour for OS X vs. Linux?
  • Using at command in shell script for scheduling a command
  • Is there a method to figure out the audio channel layout in Linux?
  • Setting environment varilable for daemon / root process
  • string replacement in shell script
  • Add specific column to the end of a CSV file
  • Are there programmable automount/autofs hooks in linux/systemd?
  • Renaming files like 20141207_190822.jpg to "2014-12-07 19.08.22.jpg" in linux or MacOS X
  • undocumented kernel boot parameter?
  • using wget to mirror a website with path and subfolder that have the same name
  • Using awk to find data matching date range in text file
  • Installing xorg-x11-devel package in SLES 11 SP2
  • Setting result of find to variable, which has variables within it
  • Maximum/Minimum physical address - Linux kernel
  • Freepbx custom context outbound route
  • memcpy implementation in linux kernel
  • How to reverse a list of words in a shell string?
  • Concatenate and pass as parameter in bash
  • Add user to Docker container
  • How to add a content in a file in linux without opening the file using vi or cat command
  • Which SVN subversion can I use on linux, Mac, Windows?
  • Work with ZIP archive at Bash
  • bash script not running as expected from cron vs. shell.
  • Compare one field, Remove duplicate if value of another field is greater
  • sudoers NOPASSWD: sudo: no tty present and no askpass program specified
  • How do I use pipes and variable substitution in a shell script (for toggling haproxy active server)?
  • Linux/Unix Find Command
  • Not able to copy data in hdfs with hdfs dfs commands
  • Linux : Remove/Delete .txt files ending with exactly five digits
  • ARM assembly "retne" instruction
  • Migrate from LXC to LXD
  • sbt on linux not accepting -jvm-debug 5005
  • Supervisord events only sent to one eventlistener in pool
  • Finding all .c files in linux using grep
  • Bash Script to Comment/uncomment lines in file
  • Linux audio control web alsamixer
  • Can't remove first two encode characters using text editors in linux
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org