Last active
          August 29, 2015 14:27 
        
      - 
      
- 
        Save bertrandmartel/fd68c0373af35eaba934 to your computer and use it in GitHub Desktop. 
    [ STACK OVERFLOW ] Parse filename Temperature_XX_Volumn_XX.dat with file name values to a single csv file
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| #title :parse_file.sh | |
| #description :parse file name into a single file | |
| #author :Bertrand Martel | |
| #date :13/08/2015 | |
| file_list=`ls $1` | |
| IFS=$'\n' #line delimiter | |
| #empty your output file | |
| cp /dev/null "$2" | |
| for i in $file_list; do | |
| #get temperature between _ and _ | |
| temperature=`echo $i | awk -v FS="([_]|[_])" '{print $2}'` | |
| #remove everything before Volumn | |
| second_part=`echo $i | sed 's/.*Volumn//'` | |
| #get volume between _ and . | |
| volume=`echo $second_part | awk -v FS="([_]|[.])" '{print $2}'` | |
| new_line="$temperature;$volume" | |
| #append to file | |
| echo $new_line >> "$2" | |
| done | |
| cat "$2" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment