transforming data using sed commands

Joe Fosteson

I need to transform xxx#yyy@zzz to look like ZZZ xxx-yyy using a script. I am already using a case statement in the script, so should I use an if statement before the case statement or should I continue with the case statement? here is my current script

function usage
{
  echo "usage: $0 arguments ..."
  if [ $# -eq 1 ]
  then echo "ERROR: $1"
  fi
}

# Script begins here
if [ $# -gt 0 ]
then
  echo "Joe Fosteson"
  date
  echo
   for arg
  do
    case $arg in
      rootjobs)
        echo "Root is running $(ps -U root -u root u | wc -l) processes on $(una
me)."
         ;;
      student_accounts)
        echo "There are $(ls -1 /home/student/ | wc -l) student accounts on $(ho
stname)."
         ;;
      *)
        usage  "Do not know what to with $arg"
         ;;
    esac

    echo "*****"
  done
else
  usage

fi

Here is the sed commands i was using but it is not correct format........

if [ $# -eq 0 ]
then echo "Please enter a file name"
else echo
 if test -f $1
  then
    #s1.sh
    starting_data=$1
    sed 's/ //' $starting_data > raw_dataz
    sed "/^id/ d" raw_dataz > new
    cut -f1 -d, new > id1
    sed 's/ //' id1 > id2
    cut -f2 -d, new > lastname1
    sed 's/ //' lastname1 > lastname2
    cut -f3 -d, new > firstname1
    sed 's/ //' firstname1 > firstname2
    awk '{print $0":"}' lastname2 > lastname3
    sed -e 's/-//g' id2 > id3
    paste -d\  firstname2 lastname3 id3 > final
    cat final
  else echo "$1 cannot be found"
 fi
fi
ooga

To convert a string like xxx#yyy@zzz to ZZZ xxx-yyy in bash:

str='xxx#yyy@zzz'
if [[ "$str" =~ (.+)#(.+)@(.+) ]]; then
  str2="${BASH_REMATCH[3]^^} ${BASH_REMATCH[1]}-${BASH_REMATCH[2]}"
  echo "$str2"
else
  echo "Bad string format"
fi

In sed

sed -r 's/(.+)#(.+)@(.+)/\U\3\E \1-\2' <<<"$str"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Transforming CSV file using sed

From Dev

transforming json data using recursion

From Dev

transforming json data using recursion

From Dev

Transforming nested xml data using xslt

From Dev

Transforming pandas data frame using stack function

From Dev

Transforming data

From Dev

data.table: Using with=False and transforming function/summary function?

From Dev

Should the action or store be responsible for transforming data when using React + Flux?

From Dev

Should the action or store be responsible for transforming data when using React + Flux?

From Dev

Using multiple sed commands for text manipulation

From Dev

Transforming data for kmeans and PCA

From Dev

Transforming a simple data frame

From Dev

Transforming Data into a timeline

From Dev

Transforming collection using lodash

From Dev

Cutting a string using multiple delimiters using the awk or sed commands

From Dev

Split data using sed or awk

From Dev

Format Data using sed or awk

From Dev

using unix commands like grep and sed for the perl array

From Dev

Using sed to insert latex commands around headers of a document

From Dev

Remove field from file using commands like awk, sed

From Dev

using unix commands like grep and sed for the perl array

From Dev

Transforming panel data in R/Excel

From Dev

Transforming data in a column to transactions in R

From Dev

Data transforming style of label in a tablerow

From Dev

Transforming Table data into new view

From Dev

Excel 2013 - Transforming data in Excel

From Dev

transforming range data to mean in R

From Dev

Transforming Immutable.js List of Maps to a List of Lists and then using this as data for google charts

From Dev

transforming XML having column wise data into row wise table form using XSLT

Related Related

  1. 1

    Transforming CSV file using sed

  2. 2

    transforming json data using recursion

  3. 3

    transforming json data using recursion

  4. 4

    Transforming nested xml data using xslt

  5. 5

    Transforming pandas data frame using stack function

  6. 6

    Transforming data

  7. 7

    data.table: Using with=False and transforming function/summary function?

  8. 8

    Should the action or store be responsible for transforming data when using React + Flux?

  9. 9

    Should the action or store be responsible for transforming data when using React + Flux?

  10. 10

    Using multiple sed commands for text manipulation

  11. 11

    Transforming data for kmeans and PCA

  12. 12

    Transforming a simple data frame

  13. 13

    Transforming Data into a timeline

  14. 14

    Transforming collection using lodash

  15. 15

    Cutting a string using multiple delimiters using the awk or sed commands

  16. 16

    Split data using sed or awk

  17. 17

    Format Data using sed or awk

  18. 18

    using unix commands like grep and sed for the perl array

  19. 19

    Using sed to insert latex commands around headers of a document

  20. 20

    Remove field from file using commands like awk, sed

  21. 21

    using unix commands like grep and sed for the perl array

  22. 22

    Transforming panel data in R/Excel

  23. 23

    Transforming data in a column to transactions in R

  24. 24

    Data transforming style of label in a tablerow

  25. 25

    Transforming Table data into new view

  26. 26

    Excel 2013 - Transforming data in Excel

  27. 27

    transforming range data to mean in R

  28. 28

    Transforming Immutable.js List of Maps to a List of Lists and then using this as data for google charts

  29. 29

    transforming XML having column wise data into row wise table form using XSLT

HotTag

Archive